Getting Confused with SonataUserBundle FosUserBundle andMYown Bundle/**

5,555 views
Skip to first unread message

Firewall Breaker

unread,
Jan 15, 2012, 10:38:50 PM1/15/12
to sonata-users
I am really getting confused with three things

FOSUserBundle
SonataAdminBundle
SonataUserBundle


1. I have my own class User.php with extended attributes like
FirstName.
2. I also created Registration Form for that Class and mapping is done
with ORM
3. The database tableis generated "fos_user" and when i fill login
form the user gets created there

1. SonatauserBundle has laso its own User.php in Application namespace
2. Database table generated by it is "fos_user_user"
3. In the Admin backend when i craete user they get inserted in
"fos_user_user"

The Problems are

1. There are two tables of users
2. The exteneded attributes i made in Acme/....User.php are not
appearing in sonata backend admin
3. When i try to login /admin/login then credentails are checked
against "fos_user" table rather than "fos_user_user"
4. I could not find in SonataUserBundle where they have done Doctrine
ORM mapping so that i can see where fos_user_user is defined. it is
not in Application/....Sonata/User.php


What sould i do.

1.Do i need to use either Acme../User.php or Application/sonata.../
User.php or i can use both
2.Do i need to create Registration from in Application../Sonata//
directory as well
3.DO i have to extend Acme/user.php from Application..../Sonata/
User.php or vice versa


Plese help

m2mdas

unread,
Jan 16, 2012, 5:35:12 AM1/16/12
to sonata-users
If you have your own User entity then you don't have to generate
userbundle in Application namespace. Just have to create following
parameter in services.yml in your bundle.

sonata.user.admin.user.entity: path\of\your\User\Entity

Checkout Resource/config/admin_orm.xml in Sonata user bundle for more
configuration options.

On Jan 16, 9:38 am, Firewall Breaker <firewall.brea...@gmail.com>
wrote:

Firewall Breaker

unread,
Jan 16, 2012, 6:52:31 AM1/16/12
to sonata-users
I did that but still when i go to backend i see the same users which
were made using Appplication bundle.
Are there more settings to do. Please help me. I am stuck for 2 days
> > Plese help- Hide quoted text -
>
> - Show quoted text -

m2mdas

unread,
Jan 16, 2012, 7:42:02 AM1/16/12
to sonata-users
I am assuming that registerbundles() function of your app/
appKernel.php looks like following

................
new Sonata\UserBundle\SonataUserBundle('FOSUserBundle'),
................
new Application\Sonata\UserBundle\ApplicationSonataUserBundle(),
..................

If so then replace first line with

new Sonata\UserBundle\SonataUserBundle(),

And comment out the second line. Then clear the cache and try. If that
does not work then go to root directory in command-line and issue the
following command and send the output.

php app/console sonata:admin:explain sonata.user.admin.user


On Jan 16, 5:52 pm, Firewall Breaker <firewall.brea...@gmail.com>

Firewall Breaker

unread,
Jan 16, 2012, 8:17:06 AM1/16/12
to sonata-users
Thanks for replying

I tried puting parameter in mybundle/services.yml like this

parameters:
sonata.user.admin.user.entity: Sangat\CoreBundle\Entity\User

But i think system was not picking that . So i had to manually chnage
the admin_orm.xml file
---------------------------------------------------------------------
<parameter key="sonata.user.admin.user.entity">Sangat\CoreBundle\Entity
\User</parameter>
---------------------------------------------------------------------

Also on the main page i am getting this error
-------------------------------------------------------------------------------
----Unable to find the snapshot : /admin/sonata/user/user/list
---------------------------------------------------------------------


Then here is the ouput of your command

AdminBundle Information
id : sonata.user.admin.user
Admin : Sonata\UserBundle\Admin\Entity\UserAdmin
Model : Sangat\CoreBundle\Entity\User
Controller : SonataAdminBundle:CRUD
Model Manager : Sonata\DoctrineORMAdminBundle\Model
\ModelManager
Form Builder : Symfony\Component\Form\FormBuilder
Datagrid Builder : Sonata\DoctrineORMAdminBundle\Builder
\DatagridBuilder
List Builder : Sonata\DoctrineORMAdminBundle\Builder
\ListBuilder

Routes
- admin_sangat_core_user_list
- admin_sangat_core_user_create
- admin_sangat_core_user_batch
- admin_sangat_core_user_edit
- admin_sangat_core_user_delete
- admin_sangat_core_user_show

Datagrid Columns
- batch batch
SonataAdminBundle:CRUD:list__batch.html.twig
- username text
SonataAdminBundle:CRUD:base_list_field.html.twig
- email text
SonataAdminBundle:CRUD:base_list_field.html.twig
- enabled boolean
SonataAdminBundle:CRUD:list_boolean.html.twig
- locked boolean
SonataAdminBundle:CRUD:list_boolean.html.twig
- createdAt text
SonataAdminBundle:CRUD:base_list_field.html.twig
- impersonating string
SonataUserBundle:Admin:Field/impersonating.html.twig

Datagrid Filters
- username doctrine_orm_string
- locked doctrine_orm_boolean
- email doctrine_orm_string
- id doctrine_orm_number

Form theme(s)
- SonataDoctrineORMAdminBundle:Form:form_admin_fields.html.twig

Form Fields



---------------------------------------------------------------------

[ErrorException]
Warning: class_parents(): object or string expected in /home/symfony/
public_html/Symfony/vendor/doctrine/lib/Doctrine/ORM/Mapping/
ClassMetadataFactory.php line 223
---------------------------------------------------------------------
> > > - Show quoted text -- Hide quoted text -

m2 m

unread,
Jan 16, 2012, 8:25:51 AM1/16/12
to sonata...@googlegroups.com
Refresh the admin dashboard page again and then goto list page. url should be changed from   /admin/sonata/user/user/list  to   /admin/sangat/user/user/list.

--
You received this message because you are subscribed to the Google Groups "sonata-users" group.
To post to this group, send email to sonata...@googlegroups.com.
To unsubscribe from this group, send email to sonata-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sonata-users?hl=en.


Firewall Breaker

unread,
Jan 16, 2012, 8:42:51 AM1/16/12
to sonata-users
I am not getting to my /admin/login page. I get his error

An exception has been thrown during the rendering of a template
("Route "sonata_page_esi_cache" does not exist.") in
SonataPageBundle::layout.html.twig at line 99.

On Jan 16, 5:25 am, m2 m <m2m...@gmail.com> wrote:
> Refresh the admin dashboard page again and then goto list page. url should
> be changed from   /admin/sonata/user/user/list  to
>  /admin/sangat/user/user/list.
>
> On Mon, Jan 16, 2012 at 7:17 PM, Firewall Breaker <
>
>
>
> firewall.brea...@gmail.com> wrote:
> > Thanks for replying
>
> > I tried puting parameter in mybundle/services.yml like this
>
> > parameters:
> >    sonata.user.admin.user.entity: Sangat\CoreBundle\Entity\User
>
> > But i think system was not picking that . So i had to manually chnage
> > the admin_orm.xml file
> > ---------------------------------------------------------------------
> > <parameter key="sonata.user.admin.user.entity">Sangat\CoreBundle\Entity
> > \User</parameter>
> > ---------------------------------------------------------------------
>
> > Also on the main page i am getting this error
>
> > ---------------------------------------------------------------------------­----
> >http://groups.google.com/group/sonata-users?hl=en.- Hide quoted text -

Firewall Breaker

unread,
Jan 16, 2012, 8:59:29 AM1/16/12
to sonata-users
I fixed that by adding tihs to routing.xml
sonata_page_cache:
resource: '@SonataPageBundle/Resources/config/routing/cache.xml'
prefix: /



But when i click on add user in dashboard then i get this error

--------------------------------------------------------------------
Warning: class_parents() [<a href='function.class-
parents'>function.class-parents</a>]: object or string expected in /
home/symfony/public_html/Symfony/vendor/doctrine/lib/Doctrine/ORM/
Mapping/ClassMetadataFactory.php line 223
500 Internal Server Error - ErrorException
----------------------------------------------------------------------------------------------------------------------------

Thomas Rabaix

unread,
Jan 16, 2012, 9:01:06 AM1/16/12
to sonata...@googlegroups.com
The sonata_page_esi_cache is used by the PageBundle. So in your sonata_page configuration you need either to disable the esi_cache or to include the correct routing file.

I have updated the documentation with the missing route file


sonata_page_cache:
    resource: '@SonataPageBundle/Resources/config/routing/cache.xml'
    prefix: /


--
Thomas Rabaix



Firewall Breaker

unread,
Jan 16, 2012, 9:12:13 AM1/16/12
to sonata-users
Thanks Thomas froa dding that to documentaion. It will be helful to
new users of documentation.
In my admin dashboard i can see my new users but when i click on Add
new then i get this error

--------------------------------------------------------------------
Warning: class_parents() [<a href='function.class-
parents'>function.class-parents</a>]: object or string expected in /
home/symfony/public_html/Symfony/vendor/doctrine/lib/Doctrine/ORM/
Mapping/ClassMetadataFactory.php line 223
500 Internal Server Error - ErrorException
---------------------------------------------------------------------------­-------------------------------------------------







On Jan 16, 6:01 am, Thomas Rabaix <thomas.rab...@gmail.com> wrote:
> The sonata_page_esi_cache is used by the PageBundle. So in your sonata_page configuration you need either to disable the esi_cache or to include the correct routing file.
>
> I have updated the documentation with the missing route file
>
> http://sonata-project.org/bundles/page/master/doc/reference/installat...
>
> sonata_page_cache:
>     resource: '@SonataPageBundle/Resources/config/routing/cache.xml'
>     prefix: /
>
> --
> Thomas Rabaix
> thomas.rab...@gmail.com
> >>>http://groups.google.com/group/sonata-users?hl=en.-Hide quoted text -
>
> >> - Show quoted text -
>
> > --
> > You received this message because you are subscribed to the Google Groups "sonata-users" group.
> > To post to this group, send email to sonata...@googlegroups.com.
> > To unsubscribe from this group, send email to sonata-users...@googlegroups.com.
> > For more options, visit this group athttp://groups.google.com/group/sonata-users?hl=en.- Hide quoted text -

Thomas Rabaix

unread,
Jan 16, 2012, 9:18:34 AM1/16/12
to sonata...@googlegroups.com
This issue is coming from Doctrine itself. You can add a var_dump + die inside the ClassMetadataFactory.php class the trace you get from symfony.

I guess something is wrong with the mapping hierarchy.


--
Thomas Rabaix



m2mdas

unread,
Jan 16, 2012, 9:30:53 AM1/16/12
to sonata-users
In configureFormFields function of UserAdmin.php comment out the
following lines

->with('Groups')
->add('groups', 'sonata_type_model', array('required'
=> false))
->end()

It would be better to create a new class that extends the Admin class,
customize and then point it by adding following parameter in
services.yml

sonata.user.admin.user.class: path\Of\Your\Admin\Class

This way you would not have to change the core bundle.

On Jan 16, 8:18 pm, Thomas Rabaix <thomas.rab...@gmail.com> wrote:
> This issue is coming from Doctrine itself. You can add a var_dump + die inside the ClassMetadataFactory.php class the trace you get from symfony.
>
> I guess something is wrong with the mapping hierarchy.
>
> --
> Thomas Rabaix
> >>>>>http://groups.google.com/group/sonata-users?hl=en.-Hidequoted text -
>
> >>>> - Show quoted text -
>
> >>> --
> >>> You received this message because you are subscribed to the Google Groups "sonata-users" group.
> >>> To post to this group, send email to sonata...@googlegroups.com.
> >>> To unsubscribe from this group, send email to sonata-users...@googlegroups.com.
> >>> For more options, visit this group athttp://groups.google.com/group/sonata-users?hl=en.-Hide quoted text -
>
> >> - Show quoted text -
>
> > --
> > You received this message because you are subscribed to the Google Groups "sonata-users" group.
> > To post to this group, send email to sonata...@googlegroups.com.
> > To unsubscribe from this group, send email to sonata-users...@googlegroups.com.
> > For more options, visit this group athttp://groups.google.com/group/sonata-users?hl=en.
>
> ...
>
> read more »

Firewall Breaker

unread,
Jan 16, 2012, 9:33:47 AM1/16/12
to sonata-users

This is ORM mapping from config file
---------------------------------------------------------------------------------------------
orm:
auto_generate_proxy_classes: %kernel.debug%
entity_managers:
default:
auto_mapping: true
mappings:
SonataUserBundle: ~
ApplicationSonataNewsBundle: ~
SonataMediaBundle: ~
ApplicationSonataMediaBundle: ~
ApplicationSonataPageBundle: ~
SonataPageBundle: ~
------------------------------------------------------------------------------------------------------------------

Now i have not included my bundle there i.e
****SangatCoreBundle:~**********

DO i need to do it in above config. Is there any other place mapping
information can be checked

m2mdas

unread,
Jan 16, 2012, 9:37:27 AM1/16/12
to sonata-users
Also if you don't want group feature you can disable it. I have
disabled it by adding following lines in services.yml

services:
-------------------------------------------
sonata.user.admin.group:
abstract: true
public: false

@Thomas: Is there any other way to disable a service?
> ...
>
> read more »

Firewall Breaker

unread,
Jan 16, 2012, 9:44:53 AM1/16/12
to sonata-users
Thanks m2mdas that commenting out thing worked fine.

I think you are right i will make my own admin class. But i have one
issue. Whatever i write in services.yml its not overriding in
admin_orm.xml file

-------------------------------------------------------------------
parameters:
sonata.user.admin.user.entity: Sangat\CoreBundle\Entity\User
-----------------------------------------------------------------------------------

I have to chnage the core file.

---------------------------------------------------------------------
<parameter key="sonata.user.admin.user.entity">Sangat\CoreBundle
\Entity
\User</parameter>
---------------------------------------------------------------------


is there any solution for this

m2mdas

unread,
Jan 16, 2012, 10:00:02 AM1/16/12
to sonata-users
Oh, forgot to mention one thing. I have overridden the sonata
userbundle and re-defined the parameters in the services.yml of that
bundle. Check out this link http://symfony.com/doc/current/cookbook/bundles/inheritance.html.
I had also pulled my hair for same problem. This is also my first
project in symfony2. Still learning actually :). Happy coding :).

On Jan 16, 8:44 pm, Firewall Breaker <firewall.brea...@gmail.com>
wrote:

Firewall Breaker

unread,
Jan 16, 2012, 10:48:58 AM1/16/12
to sonata-users
I also veyr much pulled my hair to keep that thing working. i think i
would have wasted more days if you didn't helped me.
But i still could not overirde admin_orm.xml file. I am comfortable
with yml and find it hard to convert xml to yml.

how did you do it. can give me the sample of yml file. i tried this in
my services.yml but failed
------------------------------------
sonata.user.admin.user:
class:Sangat\CoreBundle\Admin\Entity\UserAdmin
------------------------------------------------

m2mdas

unread,
Jan 16, 2012, 10:56:17 AM1/16/12
to sonata-users
My services.yml of overridden sonata user bundle http://pastebin.com/fypui5CM
.

On Jan 16, 9:48 pm, Firewall Breaker <firewall.brea...@gmail.com>
wrote:

Firewall Breaker

unread,
Jan 16, 2012, 11:27:06 AM1/16/12
to sonata-users
Thanks m2m i copied that in my services.yml but it didn't worked but
if i copy in app/config.yml then it worked

On Jan 16, 7:56 am, m2mdas <m2m...@gmail.com> wrote:
> My services.yml of overridden sonata user bundlehttp://pastebin.com/fypui5CM
> > ------------------------------------------------- Hide quoted text -

full_metal

unread,
Jun 11, 2012, 3:38:58 AM6/11/12
to sonata...@googlegroups.com
@Babban, @m2mdas,
I am so happy to have stumbled upon this conversation.

I have not figured out a way to convert 'sonata.user.admin.user' to my own admin class. 
Your gist gives a 404, can you please paste it again? 

Warm Regards,
Amit

full_metal

unread,
Jun 11, 2012, 8:48:39 AM6/11/12
to sonata...@googlegroups.com
No worries, 
I got it working :)

Pierre de LESPINAY

unread,
Jun 27, 2012, 9:31:56 AM6/27/12
to sonata...@googlegroups.com
I have exactly the same original problem and just saw your question

- FOSUser, SonataAdmin, SonataUser activated + Application extension (/aap/Application/Sonata/...) + my UserBundle
- Tables fos_user used in authentication and fos_user_user used in sonata admin

In my AppKernel.php I tried to replace
    new Sonata\UserBundle\SonataUserBundle('GlideUserBundle'),
    new Application\Sonata\UserBundle\ApplicationSonataUserBundle(),
by
    new Sonata\UserBundle\SonataUserBundle(),
#    new Application\Sonata\UserBundle\ApplicationSonataUserBundle(),
I get
Fatal error: Call to a member function getMetadataFactory() on a non-object in /var/www/Symfony/vendor/bundles/Sonata/DoctrineORMAdminBundle/Model/ModelManager.php on line 49 

What could be wrong ?

Pierre de LESPINAY

unread,
Jul 2, 2012, 7:22:02 AM7/2/12
to sonata...@googlegroups.com
I solved it by removing my UserBundle and using Application/Sonata/... instead
Entirely followed this tutorial.

Damien Favre

unread,
Nov 4, 2012, 3:49:47 PM11/4/12
to sonata...@googlegroups.com
Thanks for this discussion it helped me with my issues ( groups.google.com/forum/?fromgroups=#!topic/sonata-users/PvIG8x0QCAI )

Jérôme Bosman

unread,
May 31, 2013, 10:08:15 AM5/31/13
to sonata...@googlegroups.com
Add class like the following and you want have to hardcode the admin_orm.xml

sonata.user.admin.user.entity: 

         class:  iD\CoreBundle\Entity\User

Reply all
Reply to author
Forward
0 new messages