缺少动作'编辑'在SonataAdminBundle

时间:2014-11-04 04:55:19

标签: php symfony sonata-admin

为什么SonataAdminBundle操作列表没有操作'编辑'。只有一个'删除'。在教程中,我看到这个动作应该是prisutstyvat默认的。如何在管理页面中添加此操作? 我的UserAdmin.php:

<?php
// src/Acme/DemoBundle/Admin/PostAdmin.php

namespace Acme\AdminBundle\Admin;
use Sonata\AdminBundle\Route\RouteCollection;
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;

class UserAdmin extends Admin
{
    protected $baseRoutePattern = 'users';


    // Fields to be shown on create/edit forms
    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->add('first_name', 'text')
            ->add('last_name', 'text')
            ->add('username', 'text')
            ->add('email', 'text')
            ->add('plainPassword', 'password')
            ->add('roles','choice',array('choices'=>$this->getConfigurationPool()->getContainer()->getParameter('security.role_hierarchy.roles'),'multiple'=>true ));

        ;
    }

    // Fields to be shown on filter forms
    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
    {
        $datagridMapper
            ->add('id')
            ->add('first_name')
            ->add('last_name')
            ->add('username')
            ->add('email')

        ;
    }
    // Fields to be shown on lists
    protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper
            ->add('id')
            ->add('first_name')
            ->add('last_name')
            ->add('username')
            ->add('email')
            ->add('roles')
        ;
    }


}

2 个答案:

答案 0 :(得分:1)

您可以通过在configureFormFields的$ formMapper中调用add方法轻松添加或删除操作

 /**
 * @param ListMapper $listMapper
 */
protected function configureListFields(ListMapper $listMapper)
{
    $listMapper
        ->add('_action', 'actions', array(
            'actions' => array(
                'edit' => array(),
                'delete' => array(),
            )
        ))
    ;
}

答案 1 :(得分:0)

如果您不喜欢操作按钮,也可以使用addIdentifier()而不是add()。

// addIdentifier allows to specify that this column will provide a link to the entity's edition
$listMapper->addIdentifier('name');

http://sonata-project.org/bundles/admin/master/doc/reference/action_list.html