Sonata Admin中的自定义批处理操作

Mas*_*iro 5 symfony sonata-admin

我已经发布了这3次,似乎看不到帖子不知道我做错了什么.

我创建了我的批处理操作,我的管理类如下:

namespace ACME\MyBundle\Admin;

use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Show\ShowMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Validator\ErrorElement;
use Sonata\AdminBundle\Route\RouteCollection;

class JournalistProfileAdmin extends Admin
{
  ...........
  ...........
    public function getBatchActions()
{

    $lists = $this->getModelManager()->createQuery('ACME\MyBundle\Entity\ContactList', 'c')->execute();
    $listsArray = array();

    foreach ($lists as $list)
    {
        $listsArray[$list->getId()] = $list->getName();
    }
    $actions = parent::getBatchActions();

    $actions['addToGroup'] = array(
            'label' => $this->trans('action_add_to_group', array(), 'SonataAdminBundle'),
            'ask_confirmation' => true,
            'secondary' => $listsArray,
        );

    return $actions;
}
}
Run Code Online (Sandbox Code Playgroud)

然后扩展CRUDController,如下面的文件:

namespace ACME\MyBundle\Controller;

use Sonata\AdminBundle\Controller\CRUDController as Controller;
use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery as ProxyQueryInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;

class JournalistProfileAdminController extends Controller
{
  public function batchActionAddToIsRelevant()
    {
        return true;
    }
    public function batchActionAddToGroup(ProxyQueryInterface $selectedModelQuery)
     {
        ........................
      ...........................
    }
Run Code Online (Sandbox Code Playgroud)

当我尝试运行我的批处理动作,我得到索纳塔\ AdminBundle \控制器\ CRUDController :: batchActionAddToGroup方法必须创建错误.

有人可以帮忙吗?

man*_*anu 4

我认为您忘记在服务声明中指定 JournalistProfileAdminController。我刚刚遇到这个问题。服务声明应如下所示(在 Services.yml 中):

what.ever.JournalistProfileAdmin:
    class: your\classpath\Admin\JournalistProfileAdmin
    arguments: [ null, your\Bundle\Entity\JournalistProfile, 'YourBundle:Admin\JournalistProfileAdmin' ]
    calls:
        - [...]
    tags:
        - [...]
Run Code Online (Sandbox Code Playgroud)

这里最后一个论点很重要。它不应该是 SonataAdminBundle:CRUD 而是 YourBundle:JournalistProfileAdmin

你的问题很老了,但我希望有一天这会对某人有所帮助。