您好我想在sonata管理包中显示侧边栏,但是我找不到一个好例子,这是我用来在编辑模式下显示它的代码:
protected function configureSideMenu(MenuItemInterface $menu, $action, AdminInterface $childAdmin = null) {
if (!$childAdmin && !in_array($action, array('edit'))) {
return;
}
$admin = $this->isChild() ? $this->getParent() : $this;
$id = $admin->getRequest()->get('id');
$menu->addChild(
'view',
array('uri' => $admin->generateUrl('edit', array('id' => $id)))
);
$menu->addChild(
'replies',
array('uri' => $admin->generateUrl('sonata.admin.module.application.replies.list', array('id' => $id)))
);
}
但是我想让它显示在节目视图中,因为我将其显示为默认值,因为表单不应该是可编辑的。
这是我的configureShowFields
protected function configureShowFields(ShowMapper $showMapper) {
$showMapper
->add('application')
->add('denied')
->add('details', 'string', array('template' => 'MyBundle:Admin:jsonToTable.html.twig'))
;
}
答案 0 :(得分:3)
找到它,只需将正确的操作添加到configureSideMenu函数
protected function configureSideMenu(MenuItemInterface $menu, $action, AdminInterface $childAdmin = null)
{
if (!$childAdmin && !in_array($action, array('edit', 'show'))) {
return;
}
$admin = $this->isChild() ? $this->getParent() : $this;
$id = $admin->getRequest()->get('id');
$menu->addChild(
'view',
array('uri' => $admin->generateUrl('show', array('id' => $id)))
);
$menu->addChild(
'replies',
array('uri' => $admin->generateUrl('sonata.admin.module.application.replies.list', array('id' => $id)))
);
}