konrad_firm
konrad_firm

Reputation: 867

Symfony bootstrap file, I mean a file included by all other files

I want to globally do a few things in my Symfony project, for example I'd like to call

mb_internal_encoding("UTF-8");

Where is the right place to do this in Symfony? I know there are web/app.php and web/app_dev.php but these are TWO files, and I believe there must be ONE file somewhere where I can do this.

Upvotes: 2

Views: 723

Answers (1)

Ashutosh Rai
Ashutosh Rai

Reputation: 457

For global loading of any code the best place is to add in Symfony 2 is app/AppKernel.php. Add your code on top in the AppKernel.php or under the used class statements.

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

date_default_timezone_set( 'Asia/Kolkata' );
 mb_internal_encoding("UTF-8");
class AppKernel extends Kernel
{


    public function registerBundles()
    {
        $bundles = array(
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
            new Symfony\Bundle\AsseticBundle\AsseticBundle(),
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
            new Bvi\AdminBundle\BviAdminBundle(),
            new Bvi\UserBundle\BviUserBundle(),
            new FOS\UserBundle\FOSUserBundle(),
            new Kap\ContactBundle\KapContactBundle(),
            new Bvi\ApiBundle\BviApiBundle(),
            new WhiteOctober\TCPDFBundle\WhiteOctoberTCPDFBundle(),
            new Knp\Bundle\PaginatorBundle\KnpPaginatorBundle(),
        );

        if (in_array($this->getEnvironment(), array('dev', 'test'))) {
            $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
            $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
            $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
        }

        return $bundles;
    }

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

Upvotes: 2

Related Questions