php - Symfony 引导文件,我的意思是所有其他文件包含的文件

标签 php symfony symfony-2.3

我想在我的 Symfony 项目中全局做一些事情,例如我想打电话

mb_internal_encoding("UTF-8");

Symfony 中哪里是执行此操作的正确位置?我知道有 web/app.php 和 web/app_dev.php,但这是两个文件,我相信在某个地方一定有一个文件可以执行此操作。

最佳答案

对于任何代码的全局加载,最好的位置是在 Symfony 2 中添加 app/AppKernel.php。将您的代码添加到 AppKernel.php 的顶部或使用的类语句下。

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');
    }
}

关于php - Symfony 引导文件,我的意思是所有其他文件包含的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35148553/

相关文章:

ajax - 网址中的 Symfony2 Ajax app_dev.php

symfony - 如何在数据库中添加JSON字段?

php - Symfony 2 Doctrine 2 使用 inversedBy 和 mappedBy 进入多对多关系?

symfony - 无法在 SonataAdminBundle::standard_layout.html.twig 中找到模板 "SonataCoreBundle:FlashMessage:render.html.twig"

Symfony 2. 如何在 Twig 模板中捕获异常参数?

php - 从函数返回 html

php - 使用 PHP/MySQL 对时间敏感消息进行排队的最佳方法是什么?

php - Doctrine 添加了不必要的自连接

php - 登录表单 - 无法使用 php 登录

php - 以远程用户身份连接到数据库