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.
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 trying to create an entity listener to my entity like described in
http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html#entity-listeners
The reference I found in the Symfony docs is
http://symfony.com/doc/current/cookbook/doctrine/event_listeners_subscribers.html#creating-the-listener-class
which has a note talking about entity listeners.
If I put my FooListener in the same folder as the Foo entity (AppBundle\Entity in this case) and make the annotation #EventListener, the listener works. But I don't want to leave the listeners in the Entity folder, and I don't want to create extra configuration by registering the listener as a service if I don't need to. What is the best practice here?
You could try use full path to FooListener f.e.
#ORM\EntityListeners({"AppBundle\EventListener\FooListener"})
I am creating an app that will be extended by several bundles. Users will have access to different bundles based on roles. Some of these bundles will have configuration options, and I want one page with all config forms.
What I want to do is create a page that every bundle will "hook" into, and show the configuration form if the bundle has one.
There will also be a dashboard page that each bundle should "hook" into and show a dashboard widget.
Is there any way of achieving this in symfony? And if so, how?
I finally understood the The DependencyInjection Component so I guess the answer lies there. In detail, I will try to create an event in the configuration controller, and all bundles will have a subscriber to this event, and somehow have the forms available for the configuration twig file. But that is another question.
I want to generate some CRUD controllers with the following command:
php app/console generate:doctrine:crud
my problem is that I made 2 bundles (1 front end and 1 for the admin section) my entities are in the defaultbundle, but I'd like to generate the CRUD controllers in my admin bundle, is there a way to do this?
Generating CRUD controllers in a bundle different of the entity's one is, as far as I know, impossible.
Indeed, CRUD controllers generator is just here for test. But if you really want to use it, you can actually copy the controller, views and form in the other bundle. You'll just need to change the templates' paths and the namespaces at the beginning of the controller and the Form type.
I want to dynamically change my routes based on settings was stored in database, how I can do this in Symfony2?
You can use this bundle to replace Symfony default routing system to a dynamic one.