【发布时间】:2015-12-05 04:06:12
【问题描述】:
我将 FOS UserBundle 与 Sonata Admin/UserBundle 一起使用,我不想显示 FOSUserBundle 用户配置文件信息。
我可以访问 localhost/MyWebSite/web/app_dev.php/profile/edit,但是 我无法访问 localhost/MyWebSite/web/app_dev.php/profile
我有这个错误:
在 SonataUserBundle:Profile:action 中渲染模板时抛出异常(“无法为命名路由“sonata_user_profile_edit”生成 URL,因为这样的路由不存在。”) .html.twig 在第 27 行。
我不明白为什么在我请求 FOSUserBundle 个人资料 页面时会生成 Sonata 用户个人资料路由
在日志文件中我可以看到良好的生根消息:
INFO - 匹配的路由“fos_user_profile_show”。
感谢您的帮助。
我的路由文件
#FOS USER AND SONATA ADMIN ROUTES
fos_user_security:
resource: "@FOSUserBundle/Resources/config/routing/security.xml"
fos_user_profile:
resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
prefix: /profile
fos_user_register:
resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
prefix: /register
fos_user_resetting:
resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
prefix: /resetting
fos_user_change_password:
resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
prefix: /change-password
admin:
resource: '@SonataAdminBundle/Resources/config/routing/sonata_admin.xml'
prefix: /admin
_sonata_admin:
resource: .
type: sonata_admin
prefix: /admin
soanata_user:
resource: '@SonataUserBundle/Resources/config/routing/admin_security.xml'
prefix: /admin
sonata_user_impersonating:
pattern: /
defaults: { _controller: SonataPageBundle:Page:catchAll }
homepage:
pattern: /
编辑 1: 我尝试一些调试验证
当我调用 Url : localhost/MyWebSite/web/app_dev.php/profile 时,找到了 fos_user_profile_show 的好路径。
进入 FOS 控制器
..\vendor\friendsofsymfony\user-bundle\ FOS \ UserBundle\Controller\ ProfileController.php
但是在 ProfileController showAction() 函数之后,有一个调用 **Sonata UserBundle action.html.twig **
路径:...\vendor\sonata-project\user-bundle\Resources\views\Profile\action.html.twig
我不明白我的错误在哪里以及怎么可能:-( ...\vendor\friendsofsymfony\user-bundle\FOS\UserBundle\Resources\config\routing\profile.xml
<!--\vendor\friendsofsymfony\user-bundle\FOS\UserBundle\Resources\config\routing\profile.xml-->
<?xml version="1.0" encoding="UTF-8" ?>
<route id="fos_user_profile_show" path="/" methods="GET">
<default key="_controller">FOSUserBundle:Profile:show</default>
</route>
<route id="fos_user_profile_edit" path="/edit" methods="GET POST">
<default key="_controller">FOSUserBundle:Profile:edit</default>
</route>
...\vendor\sonata-project\user-bundle\Resources\config\routing\sonata_profile_1.xml
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
<route id="fos_user_profile_show" pattern="/">
<default key="_controller">SonataUserBundle:ProfileFOSUser1:show</default>
<requirement key="_method">GET</requirement>
</route>
<route id="fos_user_profile_edit_authentication" pattern="/edit-authentication">
<default key="_controller">SonataUserBundle:ProfileFOSUser1:editAuthentication</default>
</route>
<route id="fos_user_profile_edit" pattern="/edit-profile">
<default key="_controller">SonataUserBundle:ProfileFOSUser1:editProfile</default>
</route>
<route id="sonata_user_profile_show" pattern="/">
<default key="_controller">SonataUserBundle:ProfileFOSUser1:show</default>
<requirement key="_method">GET</requirement>
</route>
<route id="sonata_user_profile_edit_authentication" pattern="/edit-authentication">
<default key="_controller">SonataUserBundle:ProfileFOSUser1:editAuthentication</default>
</route>
<route id="sonata_user_profile_edit" pattern="/edit-profile">
<default key="_controller">SonataUserBundle:ProfileFOSUser1:editProfile</default>
</route>
【问题讨论】:
-
检查 xml 文件 @FOSUserBundle/Resources/config/routing/profile.xml 和 @SonataAdminBundle/Resources/config/routing/sonata_admin.xml 的路由。看起来有点混淆。确保它们不使用相同的 URL。
标签: php symfony fosuserbundle sonata-user-bundle