SonataAdmin 子管理路由在调试中可见但未找到
Posted
技术标签:
【中文标题】SonataAdmin 子管理路由在调试中可见但未找到【英文标题】:SonataAdmin child admin route visible in debug but not found 【发布时间】:2019-04-12 02:39:35 【问题描述】:php bin/console debug:router |grep postboxmessage
pt__RG__admin_mea_postbox_postboxmessage_list ANY ANY ANY /admin/mea/postbox/postboxmessage/list
pl__RG__admin_mea_postbox_postboxmessage_list ANY ANY ANY /pl/admin/mea/postbox/postboxmessage/list
en__RG__admin_mea_postbox_postboxmessage_list ANY ANY ANY /en/admin/mea/postbox/postboxmessage/list
pt__RG__admin_mea_postbox_postboxmessage_create ANY ANY ANY /admin/mea/postbox/postboxmessage/create
pl__RG__admin_mea_postbox_postboxmessage_create ANY ANY ANY /pl/admin/mea/postbox/postboxmessage/create
en__RG__admin_mea_postbox_postboxmessage_create ANY ANY ANY /en/admin/mea/postbox/postboxmessage/create
pt__RG__admin_mea_postbox_postboxmessage_batch ANY ANY ANY /admin/mea/postbox/postboxmessage/batch
pl__RG__admin_mea_postbox_postboxmessage_batch ANY ANY ANY /pl/admin/mea/postbox/postboxmessage/batch
en__RG__admin_mea_postbox_postboxmessage_batch ANY ANY ANY /en/admin/mea/postbox/postboxmessage/batch
pt__RG__admin_mea_postbox_postboxmessage_edit ANY ANY ANY /admin/mea/postbox/postboxmessage/id/edit
pl__RG__admin_mea_postbox_postboxmessage_edit ANY ANY ANY /pl/admin/mea/postbox/postboxmessage/id/edit
en__RG__admin_mea_postbox_postboxmessage_edit ANY ANY ANY /en/admin/mea/postbox/postboxmessage/id/edit
pt__RG__admin_mea_postbox_postboxmessage_delete ANY ANY ANY /admin/mea/postbox/postboxmessage/id/delete
pl__RG__admin_mea_postbox_postboxmessage_delete ANY ANY ANY /pl/admin/mea/postbox/postboxmessage/id/delete
en__RG__admin_mea_postbox_postboxmessage_delete ANY ANY ANY /en/admin/mea/postbox/postboxmessage/id/delete
pt__RG__admin_mea_postbox_postboxmessage_export ANY ANY ANY /admin/mea/postbox/postboxmessage/export
pl__RG__admin_mea_postbox_postboxmessage_export ANY ANY ANY /pl/admin/mea/postbox/postboxmessage/export
en__RG__admin_mea_postbox_postboxmessage_export ANY ANY ANY /en/admin/mea/postbox/postboxmessage/export
pt__RG__admin_mea_postbox_postboxmessage_send ANY ANY ANY /admin/mea/postbox/postboxmessage/send
pl__RG__admin_mea_postbox_postboxmessage_send ANY ANY ANY /pl/admin/mea/postbox/postboxmessage/send
en__RG__admin_mea_postbox_postboxmessage_send ANY ANY ANY /en/admin/mea/postbox/postboxmessage/send
pt__RG__admin_app_postboxthread_postboxmessage_list ANY ANY ANY /admin/app/postboxthread/id/postboxmessage/list
pl__RG__admin_app_postboxthread_postboxmessage_list ANY ANY ANY /pl/admin/app/postboxthread/id/postboxmessage/list
en__RG__admin_app_postboxthread_postboxmessage_list ANY ANY ANY /en/admin/app/postboxthread/id/postboxmessage/list
pt__RG__admin_app_postboxthread_postboxmessage_create ANY ANY ANY /admin/app/postboxthread/id/postboxmessage/create
pl__RG__admin_app_postboxthread_postboxmessage_create ANY ANY ANY /pl/admin/app/postboxthread/id/postboxmessage/create
en__RG__admin_app_postboxthread_postboxmessage_create ANY ANY ANY /en/admin/app/postboxthread/id/postboxmessage/create
pt__RG__admin_app_postboxthread_postboxmessage_batch ANY ANY ANY /admin/app/postboxthread/id/postboxmessage/batch
pl__RG__admin_app_postboxthread_postboxmessage_batch ANY ANY ANY /pl/admin/app/postboxthread/id/postboxmessage/batch
en__RG__admin_app_postboxthread_postboxmessage_batch ANY ANY ANY /en/admin/app/postboxthread/id/postboxmessage/batch
pt__RG__admin_app_postboxthread_postboxmessage_edit ANY ANY ANY /admin/app/postboxthread/id/postboxmessage/childId/edit
pl__RG__admin_app_postboxthread_postboxmessage_edit ANY ANY ANY /pl/admin/app/postboxthread/id/postboxmessage/childId/edit
en__RG__admin_app_postboxthread_postboxmessage_edit ANY ANY ANY /en/admin/app/postboxthread/id/postboxmessage/childId/edit
pt__RG__admin_app_postboxthread_postboxmessage_delete ANY ANY ANY /admin/app/postboxthread/id/postboxmessage/childId/delete
pl__RG__admin_app_postboxthread_postboxmessage_delete ANY ANY ANY /pl/admin/app/postboxthread/id/postboxmessage/childId/delete
en__RG__admin_app_postboxthread_postboxmessage_delete ANY ANY ANY /en/admin/app/postboxthread/id/postboxmessage/childId/delete
pt__RG__admin_app_postboxthread_postboxmessage_show ANY ANY ANY /admin/app/postboxthread/id/postboxmessage/childId/show
pl__RG__admin_app_postboxthread_postboxmessage_show ANY ANY ANY /pl/admin/app/postboxthread/id/postboxmessage/childId/show
en__RG__admin_app_postboxthread_postboxmessage_show ANY ANY ANY /en/admin/app/postboxthread/id/postboxmessage/childId/show
pt__RG__admin_app_postboxthread_postboxmessage_export ANY ANY ANY /admin/app/postboxthread/id/postboxmessage/export
pl__RG__admin_app_postboxthread_postboxmessage_export ANY ANY ANY /pl/admin/app/postboxthread/id/postboxmessage/export
en__RG__admin_app_postboxthread_postboxmessage_export ANY ANY ANY /en/admin/app/postboxthread/id/postboxmessage/export
php bin/控制台路由器:匹配 /en/admin/app/postboxthread/id/postboxmessage/list
[OK] 路由“en__RG__admin_app_postboxthread_postboxmessage_list”匹配
+--------------+-------------------------------------------------------------------------------------------+
| Property | Value |
+--------------+-------------------------------------------------------------------------------------------+
| Route Name | en__RG__admin_app_postboxthread_postboxmessage_list |
| Path | /en/admin/app/postboxthread/id/postboxmessage/list |
| Path Regex | #^/en/admin/app/postboxthread/(?P<id>[^/]++)/postboxmessage/list$#sD |
| Host | ANY |
| Host Regex | |
| Scheme | ANY |
| Method | ANY |
| Requirements | NO CUSTOM |
| Class | Symfony\Component\Routing\Route |
| Defaults | _controller: Mea\PostBoxBundle\Sonata\Controller\PostBoxMessageCrudController::listAction |
| | _locale: en |
| | _sonata_admin: mea.postbox.sonata.admin.thread|mea.postbox.sonata.admin.message |
| | _sonata_name: admin_app_postboxthread_postboxmessage_list |
| Options | compiler_class: Symfony\Component\Routing\RouteCompiler |
+--------------+-------------------------------------------------------------------------------------------+
这个例子部分工作,但这条路线我猜到了:)
PostBoxThreadAdmin
/**
* @inheritdoc
*/
protected function configureTabMenu(MenuItemInterface $menu, $action, AdminInterface $childAdmin = null): void
if (!$childAdmin && !in_array($action, ['edit']))
return;
$admin = $this->isChild() ? $this->getParent() : $this;
$id = $admin->getRequest()->get('id');
if ($this->isGranted('EDIT'))
$menu->addChild('Edit Thread', [
'uri' => $admin->generateUrl('edit', ['id' => $id])
]);
$menu->addChild('Messages',
$admin->generateMenuUrl('mea.postbox.sonata.admin.message.list', ['id' => $id])
);
当我尝试时
$menu->addChild('Messages',
$admin->generateMenuUrl('mea.postbox.sonata.admin.message', ['id' => $id])
);
得到
An exception has been thrown during the rendering of a template ("unable to find the route `mea.postbox.sonata.admin.thread|mea.postbox.sonata.admin.message`").
试试
$menu->addChild('Messages',
$admin->generateMenuUrl('mea.postbox.sonata.admin.thread|mea.postbox.sonata.admin.message', ['id' => $id])
);
得到
An exception has been thrown during the rendering of a template ("unable to find the route `mea.postbox.sonata.admin.thread|mea.postbox.sonata.admin.thread|mea.postbox.sonata.admin.message`").
试试
$menu->addChild('Messages',
$admin->generateMenuUrl('admin_app_postboxthread_postboxmessage_list', ['id' => $id])
);
得到
An exception has been thrown during the rendering of a template ("unable to find the route `mea.postbox.sonata.admin.thread.admin_app_postboxthread_postboxmessage_list`").
当我使用时
$menu->addChild('消息', $admin->generateMenuUrl('mea.postbox.sonata.admin.message.list', ['id' => $id]) );
显示子面板,但是当我创建新的并保存时 - 我得到了
unable to find the route `mea.postbox.sonata.admin.thread|mea.postbox.sonata.admin.message.send`
RuntimeException
in vendor/sonata-project/admin-bundle/src/Route/DefaultRouteGenerator.php (line 109)
in vendor/sonata-project/admin-bundle/src/Route/DefaultRouteGenerator.php->generateMenuUrl (line 60)
in vendor/Mea/PostBoxBundle/Sonata/Admin/PostBoxMessageAdmin.php->generateUrl (line 190)
in vendor/sonata-project/admin-bundle/src/Admin/AbstractAdmin.php->configureFormFields (line 1267)
in vendor/sonata-project/admin-bundle/src/Admin/AbstractAdmin.php->defineFormBuilder (line 1254)
in vendor/sonata-project/admin-bundle/src/Admin/AbstractAdmin.php->getFormBuilder (line 2980)
in vendor/sonata-project/admin-bundle/src/Admin/AbstractAdmin.php->buildForm (line 1311)
in vendor/sonata-project/admin-bundle/src/Controller/CRUDController.php->getForm (line 336)
in vendor/symfony/http-kernel/HttpKernel.php->editAction (line 149)
in vendor/symfony/http-kernel/HttpKernel.php->handleRaw (line 66)
in vendor/symfony/http-kernel/Kernel.php->handle (line 188)
Kernel->handle(object(Request))
in public/index.php (line 37)
Request::setTrustedHosts(explode(',', $trustedHosts));$kernel = new Kernel($env, $debug);$request = Request::createFromGlobals();$response = $kernel->handle($request);$response->send();$kernel->terminate($request, $response);
所以奏鸣曲尝试使用路由_sonata_admin:mea.postbox.sonata.admin.thread|mea.postbox.sonata.admin.message 但无法访问
【问题讨论】:
【参考方案1】:你可以这样做:
'uri' => str_replace('id',$id,'/admin/app/property/id/property-media/list')
如果您需要路线,可以通过以下方式找到:
bin/console debug:router
【讨论】:
以上是关于SonataAdmin 子管理路由在调试中可见但未找到的主要内容,如果未能解决你的问题,请参考以下文章
在 symfony sonata 管理包的不同子菜单中拆分域
Sonata admin 基于 ODM 的子管理员在基于 ORM 的管理员上