我已经遵循了这个:http://sonata-project.org/bundles/admin/master/doc/cookbook/recipe_sortable_listing.html
当我试图列出我的物品时,我得到了这个:
PHP Fatal error: Call to a member function getLastPosition() on a
non-object in
/home/tirengarfio/workspace/javierperezpla/src/Placas/FrontendBundle/Admin/ColumnaAdmin.php
on line 45, referer:
http://javierperezpla/app_dev.php/admin/placas/frontend/columna/3/edit
这是我的代码:
namespace Placas\FrontendBundle\Admin;
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Form\FormMapper;
class ColumnaAdmin extends Admin
{
public $last_position = 0;
private $container;
private $positionService;
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('name', 'text', array('label' => 'Nombre', 'required' => false))
->add('position', 'text', array('label' => 'Posición', 'required' => false))
;
}
public function setContainer(\Symfony\Component\DependencyInjection\ContainerInterface $container)
{
$this->container = $container;
}
public function setPositionService(\Pix\SortableBehaviorBundle\Services\PositionHandler $positionHandler)
{
/*It is not entering here*/
$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)
{
/*var_dump($this->postionService);die; HERE I GET NULL*/
$this->last_position = $this->positionService->getLastPosition($this->getRoot()->getClass());
$listMapper
->addIdentifier('name')
->add('enabled')
->add('_action', 'actions', array(
'actions' => array(
'move' => array('template' => 'PixSortableBehaviorBundle:Default:_sort.html.twig'),
)));
}
protected function configureRoutes(\Sonata\AdminBundle\Route\RouteCollection $collection)
{
$collection->add('move', $this->getRouterIdParameter() . '/move/{position}');
}
}
<?php
namespace Placas\FrontendBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity
*/
class Columna
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string", length=255, name="name")
*
* @var string $name
*/
protected $name;
/**
* @Gedmo\SortablePosition
* @ORM\Column(name="position", type="integer")
*/
private $position;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
* @return Column
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set position
*
* @param integer $position
* @return Columna
*/
public function setPosition($position)
{
$this->position = $position;
return $this;
}
/**
* Get position
*
* @return integer
*/
public function getPosition()
{
return $this->position;
}
sonata.admin.columna:
class: Placas\FrontendBundle\Admin\ColumnaAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: "Contenido web", label: "Columna" }
arguments:
- ~
- Placas\FrontendBundle\Entity\Columna
- 'PixSortableBehaviorBundle:SortableAdmin' # define the new controller via the third argument
calls:
- [ setTranslationDomain, [PlacasFrontendBundle]]
答案 0 :(得分:0)
您应该致电setPositionService()
:
sonata.admin.columna:
class: Placas\FrontendBundle\Admin\ColumnaAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: "Contenido web", label: "Columna" }
arguments:
- ~
- Placas\FrontendBundle\Entity\Columna
- 'PixSortableBehaviorBundle:SortableAdmin' # define the new controller via the third argument
calls:
- [ setTranslationDomain, [PlacasFrontendBundle]]
- [ setPositionService, [@pix_sortable_behavior.position]]
pix_sortable_behavior.position
必须是\Pix\SortableBehaviorBundle\Services\PositionHandler
的实例。
事实上,您提供的文档是:
在admin.yml中添加以下调用
- [ setContainer, [ @service_container ] ]
- [ setPositionService, [@pix_sortable_behavior.position]]