I have had FosUser bundle before and today installed SonataUserBundle. When I --dump-sql, Symfony wants to install 4 new tables:
fos_user_user
fos_user_group
for_user_user_group
notification_message
First 3 are confusing because admin already works using existing ...Entity\User class for which I even set relations.
namespace Rent\ProgramBundle\Entity;
use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity
* #ORM\Table(name="tbl_user")
*/
class User extends BaseUser
...
Why these 3 tables are installed and how to prevent that? Is there any use for them because admin section is working even without them.
By default, the SonataAdminBundle does not come with any user management, however it is most likely the application requires such feature. The Sonata Project includes a SonataUserBundle which integrates the FOSUserBundle.
The FOSUserBundle adds support for a database-backed user system in Symfony2. It provides a flexible framework for user management that aims to handle common tasks such as user login, registration and password retrieval.
The SonataUserBundle is just a thin wrapper to include the FOSUserBundle into the AdminBundle. The SonataUserBundle includes :
A default login area
A default user_block template which is used to display the current
user and the logout link
2 Admin classes : User and Group
A default class for User and Group.
There is a little magic in the SonataAdminBundle : if the bundle detects the SonataUserBundle class, then the default user_block template will be changed to use the one provided by the SonataUserBundle.
Please take a look to this document. Hope it is helpfull.
Related
Firstly, I have already searched this and tried a few solutions but none work - I may well have missed something so this is my issue.
I have three different Bundles in my Symfony 3 project, AppBundle (shared one), ClientBundle (for clients only) and AdminBundle (for admin users only). The only Entity present in the AppBundle is User.php which is extended from the FOSUserBundle in the project, as I needed extra fields. I need to be able to map a field in the User entity to a field in the Site entity which is located in the AdminBundle, but whenever I try to update the schema, I get the following error:
[Doctrine\ORM\Mapping\MappingException] The target-entity
AppBundle\Entity\Site cannot be found in
'AppBundle\Entity\User#siteId'.
Currently my mapping looks like this, in User.php:
/**
* #ORM\ManyToOne(targetEntity="\AdminBundle\Entity\Site")
* #ORM\JoinColumn(name="site_id", referencedColumnName="id")
*/
private $siteId;
As you can see, I have used the full path to the Site entity here. I have even included a use statement for the Entity, just in case:
use AdminBundle\Entity\Site;
But still the same error occurs upon schema update.
Can anyone shed any light on this? I need to be able to get this mapping to work and I cannot move the user entity to the AdminBundle as it is required by both admin and client users, and with my config set up, clients are restricted to the ClientBundle and the AppBundle.
change to targetEntity="AdminBundle\Entity\Site" (remove the leading slash)
I'm working with Symfony and FosUserBundle and I need to insert a log in my database if login is ok and before the redirection to my secured area.
I already overrode SecurityController for loginAction, but where can I insert my log ?
I don't think it's in loginAction, but I don't know how can I override login_check ?
Any ideas ?
You can doing the work indirectly with symfony layer framework. If it's good for you that use symfony you can :
use the DefaultAuthenticationSuccessHandler class symfony and read this : DefaultAuthenticationSuccessHandler
declare a service symfony with function 'onAuthenticationSuccess'
After that you can work with all symfony tools for logging all of you want.
I already use this method with FOSUserBundle.
I installed Sonata Classification bundle (part of Sonata Project Sandbox) which include Categories, Tags and Collections. Now I need create custom categories class, for example Categories for Restaurants, which should be identical to the Categories, but must contain several custom options, and save all data to another mysql table.
I can't do it in Application folder because I can't override some config files, such as routes and admin.xml, because of DI. Vendor\Sonata\ClassificationBundle have DI folder, and configs connects through Dependency Injection. I can't override it in Applications folder.
How can I perform this task??
Thank you.
If you cannot do this with doctrine, then you cannot do that with SonataAdminBundle.
I 'm a new with Symfony2!. Can you tell me please if I can user CRUD with FOSUserBundle?? Is that even possible ? Actually, i want create a Manager role who can edit and delete users form database !
FosUserBundle doesn't provide such functionality. You can generate CRUD using Symfony standard edition built in task:
php app/console doctrine:generate:crud
for your User entity.
For more complex purposes you need to check some admin bundles, maybe SonataAdminBundle . This will provide admin generator in which you can manage (CRUD) your entities.
Also note, that using all kinds of code generators is considered as not-so-good-practice
For those who are facing this issue :
- if you override the parent classe with custom fields (let's say "firstname" + "lastname") in you User entity
- and then re-generate the CRUD
you will see that the 2 custom field became editable.
The Doctrine CRUD generator looks incompatible with FOSUserBundle in the present state, as we create inheritance with a User master class.
There is a same issue if you try to use the Group Model of FOSUserBundle.
i'm creating a bundle that adds an entity and a few routes to be use in a Symfony2 application.
I want my bundle to be used as a vendor, so I've created all the files, published it on GitHub and packagist and everything works fine.
My problem is now when I require the bundle in another project, my entities and my routes are not detected:
1) php app/console doctrine:schema:update doesn't detect any modification
2) When I try to hit a GET route from the vendor, here is the error I get:
No route found for "GET ..."
Any idea is welcome, what's the process to really do these things in a bundle?
Cheers.
Cyril
Take a look at the installation steps of the FOSUserBundle for example. Everyone who uses your published bundle, have to activate it in the appkernel and import the routes. For the entity I think the bundle user have also to subclass the entity.