我尝试根据列表操作奏鸣曲admin为主页创建一个块吗?
example
dashboard:
blocks:
- { type: mea.task.block, position: center, roles: [ ROLE_WORKER ] }
这里是块渲染
class TaskListAdminBlock extends AbstractAdminBlockService
{
/**
* {@inheritdoc}
*/
public function execute(BlockContextInterface $blockContext, Response $response = null)
{
$controller = 'Mea\TaskBundle\Sonata\Controller\TaskCrudController::listAction';
$path = array(
'_controller' => $controller
);
$subRequest = $this->requestStack->getMasterRequest()->duplicate($query, null, $path);
$response = $this->kernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
return $response;
TaskCrudController是任务的奏鸣曲管理控制器
此抛出错误
There is no `_sonata_admin` defined for the controller `Mea\TaskBundle\Sonata\Controller\TaskCrudController` and the current route ``
是否可以修复此代码或以其他方式存档?
好吧,我找到了精美的解决方案这会在ajax制成的管理员列表中呈现
public function execute(BlockContextInterface $blockContext, Response $response = null)
{
$controller = 'Mea\TaskBundle\Sonata\Controller\TaskCrudController::listAction';
$path = array(
'_controller' => $controller
);
$query = [
'filter'=>[
'_per_page'=>4,
],
];
$subRequest = $this->requestStack->getMasterRequest()->duplicate($query, null, $path);
$subRequest->headers->set('X-Requested-With','XMLHttpRequest');
$subRequest->request->set('_sonata_admin','mea.task.task.admin');
$response = $this->kernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
return $response;
}
无法完全正常运行-选择Ajax模式切换操作。