Sonata Admin中的可排序功能


Sortable feature in Sonata Admin

我遵循本教程https://github.com/sonata-project/SonataAdminBundle/blob/master/Resources/doc/cookbook/recipe_sortable_listing.rst以实现Sonata管理列表中的可排序功能。

我的文件看起来像:

配置yml

sonata.admin.teh:
        class: Spts'CoreBundle'Admin'TehAdmin
        tags:
            - { name: sonata.admin, manager_type: orm, group: "Teh", label: "Something" }
        arguments:
            - ~
            - Acme'CoreBundle'Entity'Teh
            - 'PixSortableBehaviorBundle:SortableAdmin'
        calls:
            - [ setTranslationDomain, [AcmeCoreBundle]]
            - [ setContainer, [ @service_container ] ]
            - [ setPositionService, [@pix_sortable_behavior.position]]

TehAdmin.php

<?php
namespace Acme'CoreBundle'Admin;
use Sonata'AdminBundle'Admin'Admin;
use Sonata'AdminBundle'Datagrid'ListMapper;
use Sonata'AdminBundle'Datagrid'DatagridMapper;
use Sonata'AdminBundle'Form'FormMapper;
class TehAdmin extends Admin
{
    public $last_position = 0;
    private $container;
    private $positionService;
    public function setContainer('Symfony'Component'DependencyInjection'ContainerInterface $container)
    {
        $this->container = $container;
    }
    public function setPositionService('Pix'SortableBehaviorBundle'Services'PositionHandler $positionHandler)
    {
        $this->positionService = $positionHandler;
    }
    protected $datagridValues = array(
        '_page' => 1,
        '_sort_order' => 'ASC',
        '_sort_by' => 'position',
    );
// Fields to be shown on lists
    protected function configureListFields(ListMapper $listMapper)
    {
        $this->last_position = $this->positionService->getLastPosition($this->getRoot()->getClass());
        $listMapper
            ->addIdentifier('name')
            ->add('tehdan')
            ->add('_action', 'actions', array(
                'actions' => array(
                    'move' => array('template' => 'PixSortableBehaviorBundle:Default:_sort.html.twig'),
                )
            ));
        ;
    }
    protected function configureRoutes(RouteCollection $collection)
    {
        $collection->add('move', $this->getRouterIdParameter() . '/move/{position}');
    }

之后,我收到一个错误:ServiceNotFoundException:服务"sonata.admin.teh"依赖于不存在的服务"pix_portal_behavior.position"。

我缺少什么?

您可能忘记在AppKernel中添加SortableBehaviorBundle。

在app/AppKernel.php中,添加new Pix'SortableBehaviorBundle'PixSortableBehaviorBundle(),