5

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?

1
  • 4
    Why are people down voting this? its a perfectly legitimate question. Commented Oct 19, 2012 at 21:15

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

1 Comment

For the up-to-date doc, follow this link instead: symfony.com/doc/current/book/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.