我在为自己解决问题时遇到了这个问题,并决定分享解决方案,这花费了我几个小时的调试时间......
在这种情况下,生成正确 uri 的唯一方法是使用内部方法制作的不提出任何奏鸣曲建议的低级。routeGenerator
generateMenuUrl
首先,您必须调试您的应用程序中的路线(包括由奏鸣曲自动生成)。
php bin/控制台调试:路由器
例如我有 3 个嵌套级别
大厅 -> 座位方案 -> 部门
我的路线如下:
adminHall_list ANY ANY ANY /admin/hall/list
adminHall_create ANY ANY ANY /admin/hall/create
adminHall_edit ANY ANY ANY /admin/hall/{id}/edit
adminHall_delete ANY ANY ANY /admin/hall/{id}/delete
adminHall_adminScheme_list ANY ANY ANY /admin/hall/{id}/scheme/list
adminHall_adminScheme_create ANY ANY ANY /admin/hall/{id}/scheme/create
adminHall_adminScheme_edit ANY ANY ANY /admin/hall/{id}/scheme/{childId}/edit
adminHall_adminScheme_delete ANY ANY ANY /admin/hall/{id}/scheme/{childId}/delete
adminHall_adminScheme_adminSector_list ANY ANY ANY /admin/hall/{id}/scheme/{childId}/sector/list
adminHall_adminScheme_adminSector_create ANY ANY ANY /admin/hall/{id}/scheme/{childId}/sector/create
adminHall_adminScheme_adminSector_edit ANY ANY ANY /admin/hall/{id}/scheme/{childId}/sector/{childChildId}/edit
adminHall_adminScheme_adminSector_delete ANY ANY ANY /admin/hall/{id}/scheme/{childId}/sector/{childChildId}/delete
在管理类中 baseRouteName 和 baseRoutePattern 已被覆盖。
// HallSchemeAdmin.php
$this->baseRouteName = 'adminScheme';
$this->baseRoutePattern = 'scheme';
要生成最深的列表 url:
$url = $admin->getRouteGenerator()->generate('adminHall_adminScheme_adminSector_list', [
'id' => $admin->getRequest()->get('id'),
'childId' => 555, // put required id
]);
它会产生这样的网址:
/admin/hall/495/scheme/555/sector/list
如果您需要编辑 url,您也必须提供childChildId
参数:
$url = $admin->getRouteGenerator()->generate('adminHall_adminScheme_adminSector_edit', [
'id' => $admin->getRequest()->get('id'),
'childId' => 555,
'childChildId' => 12345
]);
结果是:
/admin/hall/495/scheme/555/sector/12345/edit