symfony - Symfony2, how to pass a parameter off route -
id know how pass parameter off route
route:
frontend_agences_list: path: /agences/{page} defaults: { _controller: projectfrontendbundle:frontend:listagences, page: 1 }
is ?
twig:
<a href="{{ path('frontend_agences_list') }}?mode=list"> <a href="{{ path('frontend_agences_list') }}?mode=grid"> <a href="{{ path('frontend_agences_list') }}?mode=block">
in fact, i'd display results in 3 modes, list , grid , block. in controller test ,if mode=list render "list-view.html.twig", elseif mode=grid render "grid-view.html.twig" ....
is way or there way ?
twig:
<a href="{{ path('frontend_agences_list', {'mode': 'list'}) }}">list mode</a> <a href="{{ path('frontend_agences_list', {'mode': 'grid'}) }}">grid mode</a> <a href="{{ path('frontend_agences_list', {'mode': 'block'}) }}">block mode</a>
your controller:
public function listagencesaction() { $mode = $this->get('request')->get('mode'); if($mode == 'list') { ... } }
Comments
Post a Comment