我下面的 「如何公開語義配置的軟件包」 官方手冊爲symfony1.2 2.如何使用symfony2訪問控制器中的語義配置?
我有我的configuration.php
namespace w9\UserBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
class Configuration implements ConfigurationInterface
{
/**
* {@inheritDoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('w9_user');
$rootNode
->children()
->scalarNode('logintext')->defaultValue('Zareejstruj się')->end()
->end()
;
return $treeBuilder;
}
}
而且w9UserExtension.php:
namespace w9\UserBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;
class w9UserExtension extends Extension
{
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
}
}
這可能聽起來很愚蠢,但我無法找到方法,如何訪問控制器中的logintext參數?
$logintext = $this->container->getParameter("w9_user.logintext");
不起作用。
我在做什麼錯了?
哇。謝謝。 – dunqan 2012-04-15 21:16:10
如果我有一堆配置參數會怎麼樣,我該如何設置它們全部一次? – acme 2013-09-09 15:11:19
@acme我也想這樣做。請參閱下面的答案。 – LaGoutte 2016-06-01 05:50:20