我想在我的Symfony项目中全局做一些事情,例如我想打电话
mb_internal_encoding("UTF-8");
在Symfony中,正确的地方在哪里?我知道有web / app.php和web / app_dev.php,但这些是两个文件,我相信必须有一个文件,我可以做到这一点。
答案 0 :(得分:2)
对于任何代码的全局加载,在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');
}
}