无法在Sonata Admin中生成新路线

时间:2017-01-15 13:36:46

标签: symfony sonata-admin symfony-sonata

我努力在Sonata Admnin中制作自定义操作,我按照指南Sonata documentation尝试从我的其他项目中复制代码。

我的Admin类是:

namespace BlogBundle\Admin;

use AppBundle\Form\Type\FacebookType;
use Sonata\AdminBundle\Route\RouteCollection;
use Sonata\CoreBundle\Form\Type\BooleanType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Knp\Menu\ItemInterface as MenuItemInterface;
use Sonata\AdminBundle\Admin\AdminInterface;

class PostAdmin extends AbstractAdmin
{
    protected function configureRoutes(RouteCollection $collection)
    {
        $collection->add('facebookAction');
    }

    protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper
            ->addIdentifier('id',TextType::class,[
                'label'   => 'entity.post.id'
            ])
            ->add('active',BooleanType::class,[
                'label'   => 'entity.post.active'
            ])
            ->add('_action', null, [
                'actions'          => [
                    'show'         => [],
                    'edit'         => [],
                    'delete'       => [],
                    'facebook' => [
                        'template' => 'BlogBundle:Admin:empty.html.twig'
                    ]
                ]
            ]);
        ;
    }

    //...
} 

服务声明:

services:
    admin.blog.post:
        class: BlogBundle\Admin\PostAdmin
        arguments: [~, BlogBundle\Entity\Post, BlogBundle:PostAdmin]
        tags:
            - { name: sonata.admin, manager_type: orm, label: 'admin.name.post', group: 'admin.group.blog'}

CRUD控制器:

namespace BlogBundle\Controller;

use Sonata\AdminBundle\Controller\CRUDController as Controller;

class PostAdminController extends Controller
{
    public function facebookAction()
    {

    }
}

查看分析器未生成路由,并且即使在configureListFields函数上设置了自定义路由的按钮也不会显示在列表中。

Symfony的版本是3.2.2和Sonata 3.10.3

0 个答案:

没有答案