Question

Well im just starting a new project and i choosed symfony2 as the MVC framework for it. i want first to start this project by creating a BASE with a modular architecture, i mean an empty application that contains the main and common services like (navigation tree management , activation/desactivation of modules using database , logger..) or any other global functionalites that may come later after detailed conception. my modules will later be in bundles.

what im thinking of is a Core controller that would receive all requests, do all the treatement needed, init/change the services that the modules will use depending on configurations (files or DB) and cache (session/globals) then call the called controller and return the response. to do that i have to change the kernel to always dispatch toward this controller and give the action and the controller that the user called to it.

i did some project in symfony using only the standard edition and this is the first time trying to do internal customization so i dont have a lot of experience. if anyone think that my idea is bad and have other suggestions plz give them ill be extremly greatful !

Edit : i may specify that this BASE is just tests to find the perfect modular architecture so any other idea related to modularity in symfony would be a big help ! thanks

Was it helpful?

Solution

The kernel itself has nothing to do with the controller. That's all handled by the ControllerResolver. If you always want to handle each incomming request using the same controller, you can create your own ControllerResolver to Always return an instance of that controller. See http://symfony.com/doc/current/components/http_kernel/introduction.html#resolve-the-controller for more information about controller resolving.

However, I would recommend not to do it this way. Controllers should be very tin layers between User land and Logic land. All heavy things should be done in the logic layer, in services. And if you use services, you can better register them as listeners to the kernel.controller event than to call them from within a controller. See also http://symfony.com/doc/current/cookbook/event_dispatcher/before_after_filters.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top