目前我们正在为德国经营一家网店.现在我们还希望在英国提供我们的产品,并拥有自己的域名.
根据域,它们是应加载的几个设置:
> Google Analytics ID
>付款API秘密/密钥,……
>货币
>语言
>管理员邮件
>跟踪像素(FB)
>等等……
您可以编写捆绑软件
Extension class以根据主机加载配置.
捆绑扩展:
// 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用于你的翻译,我猜).
希望这有帮助.