Add annotation with bundled entity in Symfony - symfony

I have a some entities in a Symfony bundle which has its own field configuration in the bundle.
For example: FOSUserBundle.
Now, I want to add some more configuration through annotation or xml.
For example: I want to apply some serialization parameters or Assert validation or Gedmo parameters. How can I achieve this without rewriting the whole entity?

Related

Do I need to register my Entity Listener? Where do I put it in the project?

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"})

Crud with FOSUserBundle

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.

Generating a CRUD Controller in a different bundle

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.

Create bundle without default controller and route

Is this possible to create bundle without default controller and route?
Yes, it is. Only required file in the bundle is the bundle class.
Read more in the official documentation: http://symfony.com/doc/current/book/page_creation.html#the-bundle-system

Symfony2 - how to assign Doctrine Entity as Route resource?

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.

Resources