I have a strange problem. I installed and configured SonataUserBundle to work with FosUserBundle and SonataAdminBundle. The installed went without any problems and everything seems to be working perfectly, except when I create another user via sonataUserBundle web page. Once I create the user (and it is created when I look in the database), I cannot see the users list anymore. When I click to return to the users list, I get the following error:
An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route "page_slug" as such route does not exist.") in "SonataAdminBundle:CRUD:list.html.twig".
If I delete the user from the database, to only have one user, then I can access the users list.
I have absolutely no clue on how to get further on how to resolve this issue...
Edit 1:
I found out, thanks to Marko Jurinčič that I have these lines in my config
sonata_user:
impersonating:
route: page_slug
parameters: { path: / }
However, this doesn't look like a route and effectively, there are no routes named page_slug whatsoever. Is it supposed to have a route name "page_slug" ?
I am having the same problem. What I did was to search for page_slug in my project and I found that page_slug is used in my config.yml under sonata_user
impersonating:
route: page_slug
parameters: { path: / }
I still have to take a look to see if this affects something else (I am kind of new to Symfony, so I am not 100% sure that this is not used somewhere else :) )
Commenting (or just removing) this fixed my issue and now I can see the listing of users in the admin dahsboard.
Hope it helps.
EDIT: I found the answer. In this link is explained the meaning of impersonating: https://github.com/sonata-project/SonataUserBundle/issues/174
In your case if you will not use impersonating you should just delete lines from config:
impersonating:
route: page_slug
parameters: { path: / }
(May this be found by google wanderers)
Otherwise you need to configure impersonating:
1. User needs to have role ROLE_ALLOWED_TO_SWITCH
. I configured admin to have this role:
# app/config/security.yml
security:
role_hierarchy:
ROLE_ADMIN: [ROLE_USER, ROLE_ALLOWED_TO_SWITCH]
2. Allow user switching in firewall:
# app/config/security.yml
firewalls:
main:
switch_user: true
3. (If you want a link in Sonata Admin user list) Setup SonataUserBundle - replace my_home_route
with the route name to be opened after clicking link to switch user:
# app/config/config.yml
sonata_user:
impersonating:
route: my_home_route
To manually switch user add string to url end: ?_switch_user=username
. Change username
to real username.
I saw on an approach on a website (http://www.laurent-masforne.com/memo/surcharger-sonatauserbundle-notamment-useradmin/) and commenting those lines :
/*if ($this->isGranted('ROLE_ALLOWED_TO_SWITCH')) {
$listMapper
->add('impersonating', 'string', array('template' => 'SonataUserBundle:Admin:Field/impersonating.html.twig'))
;
}*/
in vendor\sonata-project\user-bundle\Sonata\UserBundle\Admin\Model\ApplicationUserAdmin
resolved the issue. However, I don't know the impacts of doing such a thing...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With