脚本宝典收集整理的这篇文章主要介绍了php – Symfony2:根据域加载配置文件,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
根据域,它们是应加载的几个设置:
> Google Analytics ID
>付款API秘密/密钥,……
>货币
>语言
>管理员邮件
>跟踪像素(FB)
>等等……
捆绑扩展:
// src/AcmeBundle/DePEndencyInjection/AcmeExtension.PHP <?PHP namespace AcmeBundle\DependencyInjection; use Symfony\component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader; use Symfony\Component\HttpKernel\DependencyInjection\Extension; class AcmeExtension extends Extension { public function load(array $configs,ContainerBuilder $container) { $configuration = new Configuration(); $config = $this->PRocessConfiguration($configuration,$configs); $rootdir = $container->getParameter('kernel.root_dir'); // Load the bundle's services.yML $loader = new Loader\YamlFileLoader($container,new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.yml'); // Load parameters depending on current host $paramLoader = new Loader\YamlFileLoader($container,new FileLocator($rootdir.'/config')); // Access the root config directory $parameters = sprintf('parameters_%s.yml',$container->getParameter('router.request_context.host')); if (!file_exists($rootdir.'/config/'.$parameters)) { $parameters = 'parameters.yml'; // Default } $paramLoader->load($parameters); } }
相应的捆绑配置:
// src/AcmeBundle/DependencyInjection/Configuration.PHP <?PHP namespace AcmeBundle\DependencyInjection; use Symfony\Component\Config\DeFinition\Builder\TreeBuilder; use Symfony\Component\Config\DeFinition\ConfigurationInterface; class Configuration implements ConfigurationInterface { public function getConfigTreeBuilder() { $treeBuilder = new TreeBuilder(); $rootNode = $treeBuilder->root('acme'); return $treeBuilder; } }
像这样,您可以创建一个名为parameters_localhost.yml的文件,它将自动加载.
如果找不到该文件,将使用默认的parameters.yml.
你可以根据你想要的每个参数应用这个逻辑(比如_locale用于你的翻译,我猜).
希望这有帮助.
以上是脚本宝典为你收集整理的php – Symfony2:根据域加载配置文件全部内容,希望文章能够帮你解决php – Symfony2:根据域加载配置文件所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。