Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 database config in PHP file

I've been searching for a way to do this and can't figure it out.

It it possible to store the database config for Symfony2 in a PHP file?

The reason I want to do this is mainly because I usually put the entire "app" in a public directory, but also because of the way I'm attempting to structure my app.

So is there a way to do this?

like image 368
user1760047 Avatar asked Oct 06 '22 06:10

user1760047


1 Answers

Your app's configuration by default is in Yaml, but you can configure any part of Symfony to use any configuration type you want.

To configure your app to use PHP, you need to change the code that loads your configuration in the app/AppKernel.php:

public function registerContainerConfiguration(LoaderInterface $loader)
{
    $loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
}

You'll need to change this to .php and write your configuration file in PHP.

Here is what the config.php file should looks like:

$this->import('parameters.ini');
$this->import('security.yml');

$container->loadFromExtension('framework', array(
    'secret'          => '%secret%',
    'charset'         => 'UTF-8',
    'router'          => array('resource' => '%kernel.root_dir%/config/routing.php'),
    'form'            => array(),
    'csrf-protection' => array(),
    'validation'      => array('annotations' => true),
    'templating'      => array(
        'engines' => array('twig'),
        #'assets_version' => "SomeVersionScheme",
    ),
    'session' => array(
        'default_locale' => "%locale%",
        'auto_start'     => true,
    ),
));

// Twig Configuration
$container->loadFromExtension('twig', array(
    'debug'            => '%kernel.debug%',
    'strict_variables' => '%kernel.debug%',
));

You can read more about it here: http://symfony.com/doc/current/book/page_creation.html#application-configuration

like image 96
noetix Avatar answered Oct 09 '22 17:10

noetix