admin类中的configureRoutes()与Sonata \ AdminBundle \ Admin \ Admin :: configureRoutes()不兼容

时间:2016-06-02 12:39:35

标签: symfony sonata-admin

您好我正在尝试为sonata管理包创建“自定义管理操作”。但我正面临这个问题,

  

运行时通知:声明   AdminBundle \ Admin \ VideoAdmin :: configureRoutes()应该兼容   同   索纳塔\ AdminBundle \管理\管理:: configureRoutes(奏鸣曲\ AdminBundle \路径\ RouteCollection   $ collection:在c:\ wamp \ www \ videocenter \ app / config中。 (正在存在   从“C:\ wamp \ www \ videocenter \ app / config \ routing.yml”导入。)

这是我的configureRoutes()函数,

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

这是我完整的管理类,

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');
    }

}

1 个答案:

答案 0 :(得分:4)

你导入了吗?

N

我在你的VideoAdmin类

中没有看到