I use FOS UserBundle with Sonata Admin/UserBundle, and I wan't to display FOSUserBundle user profile information.
I can access to the localhost/MyWebSite/web/app_dev.php/ profile/edit , but I cannot access to localhost/MyWebSite/web/app_dev.php/ profile
I have this error :
An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route " sonata_user_profile_edit " as such route does not exist.") in SonataUserBundle:Profile:action.html.twig at line 27.
I don't understand why an Sonata user profile route was generate when I'm asking for FOSUserBundle profile page
In log file I can see the good rooting message :
INFO - Matched route "fos_user_profile_show".
Thank's for your help.
My routting file
#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: /
Edit 1 : I try some debug verification
When I call Url : localhost/MyWebSite/web/app_dev.php/ profile the good route fos_user_profile_show was find.
Go in the FOS controller
..\\vendor\\friendsofsymfony\\user-bundle\\ FOS \\ UserBundle \\Controller\\ ProfileController .php
But after ProfileController showAction() function, there is a call to **Sonata UserBundle action.html.twig **
Path : ...\\vendor\\sonata-project\\user-bundle\\Resources\\views\\Profile\\action.html.twig
I don't understand where is my mistake and how it's possible :-( ...\\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>
I did not quite figure out the whole "science" behind it yet, as FOS User and Sonata User are the most confusing bundles out there, but this will fix your problem.
Just follow this article: https://sonata-project.org/bundles/user/2-2/doc/reference/profile_edition.html
And also replace this:
fos_user_change_password:
resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
prefix: /profile
With this:
sonata_user_change_password:
resource: "@SonataUserBundle/Resources/config/routing/sonata_change_password_1.xml"
prefix: /profile
It is where I stopped so far. The next step would be to figure out what portion do you want to handle using FOS vs. Sonata and design the profile UI/UX. I see that the username & password can be changed in two different places in Profile, which is not pretty.
Use this too, it helps: http://symfony.com/doc/current/bundles/FOSUserBundle/configuration_reference.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.