后面是sonata管理员网站上的batch action documentation,创建了这个名为AnalayseController.php的自定义批量操作:
<?php
namespace Admin\Store\Receipt\ReceiptBundle\Controller;
use Sonata\AdminBundle\Controller\CRUDController as BaseController;
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
class AnalyseController extends BaseController
{
/**
* @param ProxyQueryInterface $selectedModelQuery
* @param Request $request
*
* @return RedirectResponse
*/
public function batchActionAnalyse(ProxyQueryInterface $selectedModelQuery, Request $request = null)
{
$request = $this->get('request');
$modelManager = $this->admin->getModelManager();
$target = $modelManager->find($this->admin->getClass(), $request->get('targetId'));
if ($target === null){
$this->addFlash('sonata_flash_info', 'No target!');
return new RedirectResponse(
$this->admin->generateUrl('list', $this->admin->getFilterParameters())
);
}
$selectedModels = $selectedModelQuery->execute();
$this->addFlash('sonata_flash_success', 'Done');
return new RedirectResponse(
$this->admin->generateUrl('list', $this->admin->getFilterParameters())
);
}
}
但我收到此错误:Catchable Fatal Error: Argument 1 passed to Admin\Store\Receipt\ReceiptBundle\Controller\AnalyseController::batchActionAnalyse() must implement interface Sonata\AdminBundle\Datagrid\ProxyQueryInterface, string given, called in /home/aien/Web/Mr Alef/MRA_Dev/app/cache/dev/appDevDebugProjectContainer.php on line 852 and defined
。
到处寻找,但找不到任何解决方案!
答案 0 :(得分:0)
好的,我已经通过将serives.yml calls
第一个参数更改为setTranslationDomain
admin_store_receipt_receipt.admin.analyse:
class: Admin\Store\Receipt\ReceiptBundle\Admin\ReceiptAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: admin, label: Receipt }
arguments:
- ~
- Admin\Store\Receipt\ReceiptBundle\Entity\Receipt
- AdminStoreReceiptReceiptBundle:Analyse
calls:
- [ setTranslationDomain , [AdminStoreReceiptReceiptBundle]]