1

I created a parameter in my parameters file:

parameters:
    category:
        var: test

I can access this in PHP by fetching it like this:

$var = $this->container->getParameter('category');
$var = $var['var'];

But how can I access this parameter in my config.yml? For example, I want to pass this parameter to all my twig files as a global twig variable:

twig:
    globals:
        my_var: %category.var% # throws ParameterNotFoundException

(Sidequestion:
I assumed I could access it via getParamter('category.var'), but got an error there. Do you know a nicer way than my two-liner? $this->container->getParameter('category')['var'] works, but is a syntax error according to my IDE.)

4
  • have you tried category_var ? Commented Oct 24, 2013 at 10:54
  • Yeah, I have tried that. Not working either. Commented Oct 24, 2013 at 10:56
  • 1
    here you can find answer stackoverflow.com/questions/19839157/… Commented Mar 16, 2014 at 14:36
  • 1
    If you're using NetBeans just change Project Properties -> Sources -> PHP Version to higher, because function array dereferencing has been added in PHP 5.4 (and yes, NetBeans is smart enough to check it and tell it's "syntax error"). Commented Jul 17, 2014 at 13:24

1 Answer 1

1

$this->container->getParameter('category')['var']

..is actually a pretty good way to go. Which version of PHP is your IDE using for its syntax checking? Somebody please correct me, but I think this behavior was made valid in 5.3 or 5.4.

Sign up to request clarification or add additional context in comments.

2 Comments

As for your second question, perhaps this will help you - stackoverflow.com/questions/6787895/…
I am using Aptana Studio 3. Thanks for your answer on the sidequestion, but I am more interested in the answer for the main question. The linked question does not help me as there are no nested parameters (but parameters with . inside...)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.