Skip to content

Instantly share code, notes, and snippets.

@pulse00
Created April 3, 2014 22:24
Show Gist options
  • Save pulse00/9964098 to your computer and use it in GitHub Desktop.
Save pulse00/9964098 to your computer and use it in GitHub Desktop.
Symfony2 multiple kernels
# frontend specific config in /frontend/config/config.yml
imports:
- { resource: security.yml }
...
<?php
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
// base kernel in app/AppKernel.php
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
// ...
);
return $bundles;
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
}
}
# common configuration in app/config/config.yml
imports:
- { resource: redis.yml }
- { resource: parameters.yml }
...
<?php
require __DIR__ .'/../app/AppKernel.php';
use Symfony\Component\Config\Loader\LoaderInterface;
// frontend specific kernel in frontend/FrontendKernel.php
class FrontendKernel extends \AppKernel
{
/**
* {@inheritDoc}
*/
public function registerBundles()
{
$bundles = parent::registerBundles();
$bundles[] = new FOS\JsRoutingBundle\FOSJsRoutingBundle();
return $bundles;
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
// load parent config
parent::registerContainerConfiguration($loader);
// load child-kernel config
$loader->load(__DIR__.'/config_'.$this->getEnvironment().'.yml');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment