Symfony Update routes created with Loader - symfony

I have created a route Loader that creates concrete routes that points to controller. This concrete routes are based on entities so if I create or update an entity the corresponding routes needs to be created or updated. Until now the only way of doing this is using cache:clear command but I want to avoid this in production environment. I would like to just refresh the routes collection but I'm not sure if it's possible.

Related

symfony routes: annotation vs file

What is better practise, to use annotations in Controllers or list of routes in file(s) (e.g. routes.yaml) and more importantly, Why?
I worked on big project, where you had all routes in yamls sorted by categories and every time you created new one, you had to update at least controller and some of files. I did not like it. I am hopefully starting one project and trying to decide what better option. I am considering using annotations, but I do not have enough experience yet to be sure it is right approach.
In my opinion, both are good options, and there are not an absolute truth about it. You should use the one with which you feel most comfortable.
For me, the main difference between them are:
Annotations
Keep simple the process of read and update a route, since the route and controller are in the same file, very close to each other.
You're combining in the same file controllers and routing configurations.
YAML
More difficult to read; each time you need to check the route or params, you need to look for the correct yaml file.
More organised way and separated concepts.
My final preference is to go with annotations, the main reason for that is because I don't like the yaml format at all.
It all depends
for common and simple routes to your AppBundle i suggest annotations, But for other bundles that you might want to reuse i like yaml, but the standard is xml. The reason is that the user of the third party bundle can copy the yaml/xml file, and place it in its appbundle and then he can change it and add his own version to his routing. A nice example is fosUserBundle. Imagine that you dont want a registration form because only the administrator may add new users. In that case you dont want routes to registration and would have to change route configuration
Dynamic routes
Sometimes you also need dynamic routes. SonataAdmin is a bundle that generates dynamic routes. It adds routes for each service that is tagged with sonata.admin.

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

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.

Inject additional configuration into custom Entity/Document Manager

I made a custom Document Manager for my project implementing some new low level functions (following this post).
Now I would like to inject a custom configuration in my new Document Manager (I suppose it would be the same with an Entity Manager). I have no idea of how to do this...
I want this config in my yaml files to set my custom Document Manager's parameters. The only way I found until now is to write a static function returning a hardcoded array of configuration, but it's a little dirty...)
Is there a proper way or an alternative to do this?
For defining custom configuration in the conig.yml file, use this symfony docs. You can access those configurations easily in a controller:
$this->container->getParameter(name_of_bundle_here)

Symfony2 never updated routing file automatically when generating crud

Why every single time I generate a curd for some entity , every thing works right except for last action which is updating routing file. I always get this :
Generating the CRUD code: OK Confirm automatic update of the Routing
[yes]? Importing the CRUD routes: FAILED
The command was not able to configure everything automatically.
You must do the following changes manually.
Import the bundle's routing resource in the bundle routing file ....
I know that I can do it manually as the message suggests but I want to understand why it Fails ?

Resources