Symfony bootstrap 文件,我的意思是一个被所有其他文件包含的文件
Symfony bootstrap file, I mean a file included by all other files
我想在我的 Symfony 项目中全局做一些事情,例如我想调用
mb_internal_encoding("UTF-8");
在 Symfony 中哪里是正确的地方?我知道有 web/app.php 和 web/app_dev.php 但这是两个文件,我相信一定有一个文件可以让我执行此操作。
对于任何代码的全局加载,在 Symfony 2 中添加的最佳位置是 app/AppKernel.php。在 AppKernel.php 顶部或使用的 class 语句下方添加您的代码。
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');
}
}
我想在我的 Symfony 项目中全局做一些事情,例如我想调用
mb_internal_encoding("UTF-8");
在 Symfony 中哪里是正确的地方?我知道有 web/app.php 和 web/app_dev.php 但这是两个文件,我相信一定有一个文件可以让我执行此操作。
对于任何代码的全局加载,在 Symfony 2 中添加的最佳位置是 app/AppKernel.php。在 AppKernel.php 顶部或使用的 class 语句下方添加您的代码。
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');
}
}