我想在我的 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/