[英]How can I get custom routes inside sonata admin class
I configure knp menu inside sonata admin product class and I want to add link to another admin class (category) 我在sonata admin产品类中配置了knp菜单,我想添加到另一个管理类(类别)的链接
my code is: 我的代码是:
protected function configureSideMenu(MenuItemInterface $menu, $action, AdminInterface $childAdmin = null)
{
$menu->addChild(
$this->trans('product.sidemenu.link_designer', array(), 'm2m'),
array('uri' => $admin->generateUrl('sonata.classification.admin.category.list'))
);
}
Unfortunatly route 'sonata.classification.admin.category.show' doesn't exist. 不幸的路线'sonata.classification.admin.category.show'不存在。 Routes from app/console router debug also desnt work.
来自app / console路由器调试的路由也会工作。 I have no access to inject @router in servies becouse definition of service is inside vendors.
我无法在服务中注入@router,因为服务的定义在供应商内部。
Any idea? 任何想法?
I found simple solution. 我发现简单的解决方案 I was mistake because default menu item defined in sonata demo looks like this:
我错了,因为在sonata demo中定义的默认菜单项如下所示:
$menu->addChild(
$this->trans('product.sidemenu.view_variations'),
array('uri' => $admin->generateUrl('sonata.product.admin.product.variation.list', array('id' => $id)))
);
And to add custom routes I had to added route parameter instead uri. 要添加自定义路由,我必须添加路由参数而不是uri。
$menu->addChild(
$this->trans('product.sidemenu.view_variations'),
array('route' => 'admin_sonata_classification_category_list' )
);
Now everything work . 现在一切正常。
In your admin, you can override the configureRoutes
method, as demonstrated in the documentation: 在您的管理员中,您可以覆盖
configureRoutes
方法,如文档中所示:
http://sonata-project.org/bundles/admin/2-2/doc/reference/routing.html#create-a-route http://sonata-project.org/bundles/admin/2-2/doc/reference/routing.html#create-a-route
This will allow you to add custom routes for your admin. 这将允许您为管理员添加自定义路由。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.