Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to access semantic configuration in a controller with symfony2?

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?

like image 701
dunqan Avatar asked Apr 15 '12 16:04

dunqan


1 Answers

In w9UserExtension.php after processConfiguration line just add

$container->setParameter('w9_user.logintext', $config['logintext']);
like image 119
Mun Mun Das Avatar answered Sep 22 '22 10:09

Mun Mun Das