我想在我的Symfony项目中做一些全球性的事情,例如,我想打电话给
mb_internal_encoding("UTF-8");在Symfony哪里是做这件事的合适地点?我知道有web/app.php和web/app_dev.php,但是这是两个文件,我相信肯定有一个文件可以这样做。
发布于 2016-02-02 08:56:17
对于任何代码的全局加载,最好的地方是添加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');
}
}https://stackoverflow.com/questions/35148553
复制相似问题