在自定义页面中创建自定义路由

Create a custom route in a custom page

我正在使用 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`")

我有一个实体 X,它与实体 Y 具有一对多关系。 代码说明:

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。但是当我在添加适度路由后将 $collection 转储到 YAdmin 中时,我有两个元素:

我搜索了一下,但好像没有其他人这样做过。

谢谢你的帮助

我写下 Gaska 的评论来关闭这个问题。

我只需要补充:

$collection->add('moderate', 'moderate');然后清除缓存

感谢他