I am extending the Sonata User Bundle and creating some extra fields in the new user entity. These fields will only be updated within the Sonata admin area under users so they do not need to be available in the edit profile form. I am having trouble updating these fields via the Sonata User Manager and tried several different ways to extend/implement that class in Application\Sonata\UserBundle. Has anyone encountered this before and can give me a tutorial or step by step process of the cleanest way to extend the new User entity?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
I found out the issue was a doctrine issue. My extended bundle was utilizing the original xml field mappings. I deleted those files and reverted to annotations. Everything worked brilliantly from there. I hope this helps someone else who is experiencing the same issue.
This is easy, yet the
SonataUserBundle
documentation is pretty short on this. Basically, after setting up the two bundles as described here and here:You need to create a class to extend the
Sonata\UserBundle\Entity\BaseUser
class inSonataUserBundle
. Note that if you override the constructor, you still must call the parent object's constructor.If you need to, you can also override the
Sonata\UserBundle\Entity\BaseGroup
object in a similar way.Then, edit your
config.yml
to match your namespaces, like thisClear the cache. Your entities will be used instead of the built-in ones.
1. Create a new bundle
Something like AcmeUserBundle. Create it and register it as you do normally.
2. Create a new User entity
Then create a
User
andGroup
entity which extendsSonata\UserBundle\Entity\BaseUser
andSonata\UserBundle\Entity\BaseGroup
. You should also add the configuration for the primary key, for instance:3. Configure the entity
then, go to your
app/config/config.yml
file and configure these new entities:4. Override the UserAdmin class
Then, you need to create a new UserAdmin class. To do this, just create a new
UserAdmin
class inside your bundle, extendSonata\UserBundle\Admin\Model\UserAdmin
and override the methods like this:5. Replace the old UserAdmin class
Then, you need to make sure Sonata uses the new UserAdmin class. You just need to set the
sonata.user.admin.user.class
parameter to your new class and your ready!