Oh! I forgot. For your actual request, yes, you can do the same for the
controller, just toggle "_route" with "_controller" instead.

app.request.attributes.get('_controller')

I actually post a question about this, it was because '_controller' was not
available when you call the 'render' helper to render a
controller's response (the response is another themplate of course). So if
you requested the controller inside the rendered template, it was not
available that way.

Fabien saw my email and answered that he will take a look and try to include
it, I haven't check yet (that was about 1 month ago).

Regards.
2011/5/30 oscar balladares <liebegr...@gmail.com>

> What I'm doing is to get the actual route in template, and if a route
> matchs a category (lets say),
> then print an "id='current'"
>
> for example:
>
> <li><a
>          {% if app.request.attributes.get('_route') == 'homepage'  %}
>          class='current'
>          {% endif %}
>        href="{{ path('homepage') }}">Home</a></li>
>
> That's it. Of course it will become clumsy when you have many links cause
> it is hard to read through.
> I'll go with MenuBundle in my next project update schedule.
>
> 2011/5/28 FuzzyBird <nicolas.worm...@gmail.com>
>
>> I think a good way to do it is, in the controller :
>>
>> // first generate the menu structure
>>
>>  // you may want to do the following in a loop for all your menu items
>> if ($this->get('router')->generate('some-route') === $this-
>> >get('request')->getRequestUri() ){
>>      // highlight the link of this route
>> }
>>
>> Hope it helped
>>
>> On May 12, 8:20 pm, Filipe La Ruina <filaru...@gmail.com> wrote:
>> > Hey guys,
>> > I've been searching for a way of getting the controller that was called
>> so I
>> > can highlight the menu.
>> > I looked in the HTTP Foundation class and it seems that there is no way
>> of
>> > doing it.
>> > Even searching here I couldn't find anyone that had the same problem.
>> > Well, now i'm doing it the following way (note that I need it to show
>> some
>> > element in the html and a class in an element)
>> >
>> > <ul class="menu">
>> >             <li {% if (app.request.getPathInfo  == '/foo')
>> > %}class="selected"{% endif %}>
>> >                 {% if (app.request.getPathInfo  == '/foo') %}
>> >                 <span class="border left"></span>
>> >                 {% endif %}
>> >                 <a href="{{ url('foo') }}">Foo</a>
>> >                 {% if (app.request.getPathInfo  == '/foo') %}
>> >                 <span class="border right"></span>
>> >                 {% endif %}
>> >             </li>
>> >             <li {% if (app.request.getPathInfo  == '/bar')
>> > %}class="selected"{% endif %}>
>> >                 {% if (app.request.getPathInfo  == '/bar') %}
>> >                 <span class="border left"></span>
>> >                 {% endif %}
>> >                 <a href="{{ url('bar') }}">Bar</a>
>> >                 {% if (app.request.getPathInfo  == '/bar') %}
>> >                 <span class="border right"></span>
>> >                 {% endif %}
>> >             </li>
>> > </ul>
>> >
>> > For now it is working since I don't have /foo/abc for example, all the
>> urls
>> > are /foo and /bar so the test will work.
>> > Also I think that is not a nice way of testing (actually using the url
>> and
>> > not the controller name)
>> > So is there anyway of getting the controller name on the template?
>>
>> --
>> If you want to report a vulnerability issue on symfony, please send it to
>> security at symfony-project.com
>>
>> You received this message because you are subscribed to the Google
>> Groups "symfony users" group.
>> To post to this group, send email to symfony-users@googlegroups.com
>> To unsubscribe from this group, send email to
>> symfony-users+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/symfony-users?hl=en
>>
>
>

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en

Reply via email to