我正在遵循Symfony 2官方手册中的“如何为Bundle公开语义化配置”的内容。
我有我的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");
不起作用。
我做错了什么?