2016-06-02 9 views
0

Hallo Ich versuche, "Erstellen Sie eine benutzerdefinierte Admin-Aktion" für Sonata-Admin-Bundle. Aber ich dieses Problem konfrontiert,configureRoutes() in der Admin-Klasse ist nicht kompatibel mit Sonata AdminBundle Admin Admin :: configureRoutes()

Runtime Hinweis: Erklärung AdminBundle \ Admin \ VideoAdmin :: configureRoutes() sollte mit Sonata \ AdminBundle \ Admin \ Admin :: configureRoutes (Sonata kompatibel sein \ AdminBundle \ Route \ RouteCollection $ collection) in C: \ wamp \ www \ videocenter \ app/config. (Das wird importiert von "C: \ wamp \ www \ videocenter \ app/config \ routing.yml").

Das ist mein configureRoutes() Funktion,

protected function configureRoutes(RouteCollection $collection) { 
     $collection->add('clone', $this->getRouterIdParameter() . '/clone'); 
} 

Dies ist meine komplette Admin-Klasse,

namespace AdminBundle\Admin; 

use Sonata\AdminBundle\Admin\Admin; 
use Sonata\AdminBundle\Datagrid\ListMapper; 
use Sonata\AdminBundle\Datagrid\DatagridMapper; 
use Sonata\AdminBundle\Form\FormMapper; 
use Sonata\AdminBundle\Show\ShowMapper; 
use AdminBundle\Entity\Video; 
use Doctrine\ORM\Query\ResultSetMapping; 

class VideoAdmin extends Admin { 

    protected function configureFormFields(FormMapper $formMapper) { 
     $formMapper->add('name', 'text'); 
     $formMapper->add('category', 'sonata_type_model', array(
      'class' => 'AdminBundle\Entity\VideoCategory', 
      'property' => 'name', 
     )); 
     $formMapper->add('thumbUrl', 'text'); 
     $formMapper->add('url', 'text'); 
//  $formMapper->add('videoKey', 'text'); 
     $formMapper->add('isPublic', 'checkbox', array(
      'label' => 'Show public', 
      'required' => false, 
     )); 
     $formMapper->add('isEnabled', 'checkbox', array(
      'label' => 'Enable', 
      'required' => false, 
     )); 
    } 

    protected function configureDatagridFilters(DatagridMapper $datagridMapper) { 
     $datagridMapper 
       ->add('name') 
       ->add('category', null, array(), 'entity', array(
        'class' => 'AdminBundle\Entity\VideoCategory', 
        'property' => 'name')) 
       ->add('videoKey'); 
    } 

    protected function configureListFields(ListMapper $listMapper) { 
     $listMapper 
       ->addIdentifier('name') 
       ->add('category.name') 
       ->add('url') 
       ->add('videoKey') 
       ->add('isPublic') 
       ->add('isEnabled') 
       ->add('_action', 'actions', array(
        'actions' => array(
         'show' => array(), 
         'edit' => array(), 
         'delete' => array(), 
         'clone' => array(
          'template' => 'AdminBundle:CRUD:list__action_clone.html.twig' 
         ), 
        ) 
       )) 
     ; 
    } 

    public function postPersist($object) { 
     global $kernel; 
     if ('AppCache' == get_class($kernel)) { 
      $kernel = $kernel->getKernel(); 
     } 
     $em = $kernel->getContainer()->get('doctrine.orm.entity_manager'); 

     $query = "select a.random_num from (SELECT FLOOR(RAND() * 99999) AS random_num) a WHERE A.RANDOM_NUM NOT IN (SELECT COALESCE(B.VIDEO_KEY,0) FROM VIDEO B)"; 

     $stmt = $em->getConnection()->prepare($query); 
     $stmt->execute(); 
     $randum = $stmt->fetchAll(); 

     $video = $em->getRepository('AdminBundle:Video')->find($object->getId()); 

     if ($video) { 
      $video->setVideoKey($randum[0]['random_num']); 
      $em->flush(); 
     } 
    } 

    public function toString($object) { 
     return $object instanceof Video ? $object->getName() : 'Video'; // shown in the breadcrumb on the create view 
    } 

    public function getBatchActions() { 
     // retrieve the default batch actions (currently only delete) 
     $actions = parent::getBatchActions(); 

     if (
       $this->hasRoute('edit') && $this->isGranted('EDIT') && 
       $this->hasRoute('delete') && $this->isGranted('DELETE') 
     ) { 
      $actions['merge'] = array(
       'label' => 'action_merge', 
       'translation_domain' => 'SonataAdminBundle', 
       'ask_confirmation' => true 
      ); 
     } 

     return $actions; 
    } 

    protected function configureRoutes(RouteCollection $collection) { 
     $collection->add('clone', $this->getRouterIdParameter() . '/clone'); 
    } 

} 

Antwort

3

Haben Sie importieren?

use Sonata\AdminBundle\Route\RouteCollection; 

Ich sehe nicht, dass in deiner VideoAdmin Klasse

Verwandte Themen