由于Sensio Insight的限制,我试图将参数从app/config/parameters.yml
移动到应用程序捆绑包,但仍在获取
您请求了一个不存在的参数"truckee_volunteer.sandbox"
这是因为app/config/config.yml
包含(以及来自捆绑包的parameters.yml
的其他引用)
imports:
- { resource: parameters.yml }
- { resource: @TruckeeVolunteerBundle/Resources/config/parameters.yml }
...
twig:
...
globals:
sandbox: "%truckee_volunteer.sandbox%"
此尝试基于此SO答案
扩展类
class TruckeeVolunteerExtension extends Extension
{
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
/* for Sensio Insight
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
*/
$loader = new Loader'XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.xml');
$loader = new Loader'YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('parameters.yml');
}
public function getAlias()
{
return 'truckee_volunteer';
}
配置类
class Configuration implements ConfigurationInterface
{
/**
* {@inheritDoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('truckee_volunteer');
$rootNode
->children()
->scalarNode('admin_user')
->defaultValue('admin')
->isRequired()
->cannotBeEmpty()
->end()
->scalarNode('admin_password')
->isRequired()
->cannotBeEmpty()
->end()
->arrayNode('admin_email')
->children()
->scalarNode('address')->isRequired()->cannotBeEmpty()
->end()
->end()
->scalarNode('admin_first_name')
->isRequired()
->cannotBeEmpty()
->end()
->scalarNode('admin_last_name')
->isRequired()
->cannotBeEmpty()
->end()
->booleanNode('sandbox')
->defaultFalse()
->isRequired()
->cannotBeEmpty()
->end()
->end()
;
// Here you should define the parameters that are allowed to
// configure your bundle. See the documentation linked above for
// more information on that topic.
return $treeBuilder;
}
}
Bundle的参数.yml
truckee_volunteer:
admin_user: admin
admin_password: 123Abcd
admin_email:
address: admin@example.com
admin_first_name: Benny
admin_last_name: Borko
sandbox: false
似乎只有在处理完app/config/config.yml
之后才能读取捆绑包的parameters.yml
文件。这是通过在bundle的Extension类中放置exit("Bailing out of the Extension class!!");
命令来确定的。除非app/config/config.yml
不包含任何形式为"%truckee_volunteer.*%"
的参数,否则不会运行该命令。
如果我没有编造,那么就不可能在捆绑包中定义可替换的参数。有人能证实吗?
进一步测试:
我无法完全解释或理解这种行为。如果捆绑包的parameters.yml
文件被修改为
parameters:
truckee_volunteer.admin_user: admin
truckee_volunteer.admin_password: 123Abcd
truckee_volunteer.admin_email.address: admin@bogus.info
truckee_volunteer.admin_first_name: Benny
truckee_volunteer.admin_last_name: Borko
truckee_volunteer.sandbox: false
则这些参数在CCD_ 10中是可替换的。可能还有其他要求,但经过多次试验,我还没有解决。
无论如何,我已经放弃了这种方法,因为我理解了Sensio Insight的约束,这让我开始考虑这样做。事实证明,可以扩展默认的parameters.yml.dist
,但如果包含电子邮件地址,则必须指定符合RFC的默认地址。将所有自定义参数放在parameters.yml.dist
中会更容易、更有效。