[英]Render Sonata admin list in block
I try to create a block for the main page based on list action sonata admin is possible?我尝试根据列表操作奏鸣曲管理员为主页创建一个块是可能的吗?
example
dashboard:
blocks:
- { type: mea.task.block, position: center, roles: [ ROLE_WORKER ] }
Here is block render这是块渲染
class TaskListAdminBlock extends AbstractAdminBlockService
{
/**
* {@inheritdoc}
*/
public function execute(BlockContextInterface $blockContext, Response $response = null)
{
$controller = 'Mea\TaskBundle\Sonata\Controller\TaskCrudController::listAction';
$path = [
'_controller' => $controller,
];
$subRequest = $this->requestStack->getMasterRequest()->duplicate($query, null, $path);
return $this->kernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
}
}
TaskCrudController is sonata admin controller for task TaskCrudController 是任务的奏鸣曲管理员 controller
this throw error这个抛出错误
There is no `_sonata_admin` defined for the controller `Mea\TaskBundle\Sonata\Controller\TaskCrudController` and the current route ``
Is possible to fix this code or archive this in another way?是否可以修复此代码或以其他方式存档?
Ok I found beautifully solution This renders in ajax made admin list好的,我找到了精美的解决方案这在 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;
}
Not fully work fine - ajax mode switch actions to select.不能完全正常工作 - ajax 模式切换操作到 select。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.