我按照本教程https://github.com/sonata-project/SonataAdminBundle/blob/master/Resources/doc/cookbook/recipe_sortable_listing.rst在Sonata管理员列表中实现了一项可排序功能。
我的文件如下:
config.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_sortable_behavior.position”。
我缺少什么?
答案 0 :(得分:3)
您可能忘记在AppKernel中添加SortableBehaviorBundle。
在app / AppKernel.php中,添加new Pix\SortableBehaviorBundle\PixSortableBehaviorBundle(),