简体   繁体   中英

Sortable feature in Sonata Admin

I follow this tutorial https://github.com/sonata-project/SonataAdminBundle/blob/master/Resources/doc/cookbook/recipe_sortable_listing.rst to implement a sortable feature in Sonata admin listing.

My files looks like:

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

After that I receive an error: ServiceNotFoundException: The service "sonata.admin.teh" has a dependency on a non-existent service "pix_sortable_behavior.position".

What I'm missing?

You probably forgot to add the SortableBehaviorBundle in your AppKernel.

In app/AppKernel.php, add new Pix\\SortableBehaviorBundle\\PixSortableBehaviorBundle(),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM