我已经发布了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;
}
}

然后如以下文件中所示扩展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)
     {
        ........................
      ...........................
    }

当我尝试运行批处理操作时,我得到Sonata\AdminBundle\Controller\CRUDController::batchActionAddToGroup方法必须创建错误。

谁能帮忙吗?

最佳答案

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

what.ever.JournalistProfileAdmin:
    class: your\classpath\Admin\JournalistProfileAdmin
    arguments: [ null, your\Bundle\Entity\JournalistProfile, 'YourBundle:Admin\JournalistProfileAdmin' ]
    calls:
        - [...]
    tags:
        - [...]

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

您的问题已经很老了,但我希望有一天能对某人有所帮助。

关于symfony - Sonata Admin中的自定义批处理操作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24013567/

10-09 07:25