Answer the question
In order to leave comments, you need to log in
AppKernel in Symfony 2
Recently working with Symfony 2. I have a
question.
As you know, AppKernel.php includes all the necessary bundles.
For example, in addition to the main ones, I have additional bundles for the
admin panel, for migrations (DoctrineMigrationsBundle) and some others.
When the pages of the frontend part are loaded, why are these unnecessary bundles loaded?
In addition, migrations are generally used only in the console.
Why are they loaded everywhere?
Or am I cooking it wrong? ©
Answer the question
In order to leave comments, you need to log in
At the first boot, all bundles are connected. This is done in order to form a list of services for each bundle and generally understand what is what. Therefore, a call to all available services appears in the cache, and, in theory, until the cache is cleared, the bundles will no longer be connected unnecessarily. in the dev environment, they are constantly connected just so that the list of services is up-to-date (although not a fact either).
You can separate the set of downloadable bundles using different environments
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
// ....
);
$environment = $this->getEnvironment();
if (in_array($environment, array('test', 'behat'))) {
$bundles[] = new Behat\BehatBundle\BehatBundle();
$bundles[] = new Behat\MinkBundle\MinkBundle();
}
return $bundles;
}
}
The migration bundle can be loaded in the dev environment, as By default, the console starts with this environment.
And for the rest. Do you have real performance problems due to the fact that all bundles are loaded?
It's just that the bundles themselves are almost empty classes and they should not create a load.
I've been thinking about this problem for a long time too. And I even decided to make several projects to separate the admin panel and the front-end, and took out the general functionality into my bundles and connected them in these projects. But then I realized that there is almost no point in this and right now I am doing everything together in one project.
Another idea came to mind while writing the previous comment. You can make different entry points for the admin and frontend and connect your own AppKernel in each, where each will have its own set of bundles. To be honest, I don't know how well this works. But you can try :)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question