我正在使用 Symfony 4.3 和 Sonata 3.x 版本。
我正在尝试在自定义页面中创建自定义路由,但出现错误:
An exception has been thrown during the rendering of a template ("unable to find the route `admin.photocall|admin.photocall_gallery.moderate`")
我有一个与 Y 实体有 OneToMany 关系的实体 X。用代码解释:
class XAdmin extends AbstractAdmin
{
[...]
protected function configureSideMenu(MenuItemInterface $menu, $action, AdminInterface $childAdmin = null)
{
$admin = $this->isChild() ? $this->getParent() : $this;
$id = $admin->getRequest()->get('id');
if ($this->isGranted('LIST')) {
$menu->addChild('Galerie', [
'uri' => $admin->generateUrl('admin.photocall_gallery.list', ['id' => $id])
]);
}
}
}
然后是我的 YAdmin :
class YAdmin extends AbstractAdmin
{
protected function configureListFields(ListMapper $listMapper)
{
$listMapper->add('_action', null, [
'actions' => [
'clone' => [
'template' => 'admin/PhotocallListAdmin/__list_action_moderate.html.twig'
]
]
])
;
}
protected function configureRoutes(RouteCollection $collection)
{
if ($this->isChild()) {
$collection->clearExcept(['list', 'moderate']);
$collection->add($collection->getBaseCodeRoute().'.moderate', 'moderate');
return;
}
}
}
所以在那里,我添加了一个带有如下模板的操作:
<a class="btn btn-sm" href="{{ admin.generateObjectUrl('moderate', object) }}">
{% if not object.ismoderate %}
Moderate
{% else %}
Undo moderation
{% endif%}
</a>
所以错误说它无法找到路由 admin.photocall|admin.photocall_gallery.moderate。但是当我在添加中等路由后在 YAdmin 中转储 $collection 时,我有两个元素:
admin.photocall|admin.photocall_gallery.list(当前页面)
admin.photocall|admin.photocall_gallery.moderate
我搜索过,但看起来没有其他人这样做。
谢谢你的帮助