我正在关注 symfony 2 的“如何公开捆绑的语义配置”官方手册。
我有我的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");
不起作用。
我做错了什么?