I'm following "How to expose a Semantic Configuration for a Bundle" official manual for symfony 2.
I have my 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;
}
}
And 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');
}
}
It may sounds silly, but I'm not able to find the way, how to access logintext parameter in controller?
$logintext = $this->container->getParameter("w9_user.logintext");
does not work.
What I'm doing wrong?
In w9UserExtension.php
after processConfiguration
line just add
$container->setParameter('w9_user.logintext', $config['logintext']);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With