I would like to retrieve the parameters sent by the form (method="get") and add them to the route.
This is the route:
frontend_list:
path: /travels/{page}
defaults: { _controller: ProjectFrontendBundle:Frontend:list, page: 1 }
and this is the form:
<form action="" method="get" class="form_sort" id="myForm">
<span class="manage_title">Sort by:</span>
<select class="select_styled white_select" id="sort_list" name="sort" onChange="sendForm();">
<option value="">-------</option>
<option value="country:asc">Country A-Z</option>
<option value="country:desc">Country Z-A</option>
<option value="destination:asc">City A-Z</option>
<option value="destination:desc">City Z-A</option>
</select>
</form>
and this is the controller:
public function listAction($page, Request $request)
{
$em = $this->getDoctrine()->getManager();
$nbByPage = $this->container->getParameter('travel.number_by_page');
if ($request->getMethod() == 'POST')
{
$sort = $request->query->get('sort');
list($orderBy, $orderWay) = explode(":", $sort); //explode
$listTravels = $em->getRepository('ProjectTravelBundle:Travel')->getListTravelsFrontend($nbByPage, $page, $orderBy, $orderWay);
return $this->render('ProjectFrontendBundle:Frontend:list.html.twig',array(
'listTravels' => $listTravels,
'page' => $page,
'nb_page' => ceil(count($listTravels) / $nbByPage) ?: 1
));
}
$orderBy = "id"; // set default orderBy
$orderWay = "desc"; // set default orderWay
$listTravels = $em->getRepository('ProjectTravelBundle:Travel')->getListTravelsFrontend($nbByPage, $page, $orderBy, $orderWay);
return $this->render('ProjectFrontendBundle:Frontend:list.html.twig',array(
'listTravels' => $listTravels,
'page' => $page,
'nb_page' => ceil(count($listTravels) / $nbByPage) ?: 1
));
}
So I'd like to have url like this for example when select a choice "sort" :
localhost/agence/web/app_dev.php/travels?orderby=country&orderway=aesc
Right now , I get an nonfunctional url like this when select a choice:
localhost/agence/web/app_dev.php/voyages?sort=country%3Aasc
So my question is how to add those parameters in the route frontend_list and add them to the path in twig view beside parameter page to have a correct url with pagination:
{% if nb_page > 1 %}
{% if page == 1 %}
<a class="link_prev">Previous</a>
{% else %}
<a href="{{ path('frontend_list', {'page': page - 1}) }}" class="link_prev">Previous</a>
{% endif %}
{% if page == nb_page %}
<a class="link_next">Next</a>
{% else %}
<a href="{{ path('frontend_list', {'page': page + 1}) }}" class="link_next">Next</a>
{% endif %}
{% endif %}