Houssem Houssem - 1 year ago 133
Ajax Question

symfony 3 : i want to create a slider that filter research list betwenn min val and max val

this is the view that let show range slider and the list of hotels
i want to filter research by clicking on the range

{% block body %}
<div class="container" style="width:800px;">

<div align="center">
<input type="range" min="10000" max="55000" step="1000" value="10000" id="min_price" name="min_price" />
<span id="price_range"></span>
<br /><br /><br />
<div id="product_loading">
<div class="col-md-9">
<div class="row">
{% for x in Hotels %}
<div class="col-sm-4 col-lg-4 col-md-4">
<div class="thumbnail">
<img src="{{ asset('uploads/brochures/'~x.brochure) }}" alt="">
<div class="caption">
<h4 class="pull-right">{{ x.price }}</h4>
<h4><a href="#">{{ x.titre }}</a>


{% endfor %}
var price = $(this).val();
$("#price_range").text("Product under Price Rs." + price);
url:" {{ path('Hotel__') }},
data:'price' +price ,
{% endblock %}

My problem is in AJAX ! i must specify URL and DATA Any suggestion ?
i must put on the url the view who let me to filter resut and in Date the parameters
so i do getListHotelInfBudget in Repository

public function getListHotelInfBudget($budget)
$qb = $this->createQueryBuilder('h');
->where('h.price <= :budget')
->setParameter('budget', $budget);
return $qb->getQuery()->getResult();


public function getListAction($budget)
$list =$em->getListHotelInfBudget($budget);
return $this->render('....Bundle:....:listHotel.html.twig',array('list'=>$list));

and the routing configuration :

path: /hotel/{budget}
defaults: { _controller: .......Bundle:.....:getList }

but an exception
An exception has been thrown during the rendering of a template ("Some mandatory parameters are missing ("price") to generate a URL for route

Answer Source

Your code seems to be very badly organized. How do you want to pass the price to the getListAction ?

With budget as GET parameter ? Or with price as POST parameter ?

Here your error comes because :

Your Hotel__ route needs {budget} to be generated.

In your template you call {{ path('Hotel__') }}.

So you have to define a budget :

{{ path('Hotel__',{'budget':142}) }}

But I don't think it makes sence, because your budget probably must come from the sliders and not from twig.


You can pass the price with data: {price : price }

And get it in your controller like this :

use Symfony\Component\HttpFoundation\Request;


public function getListAction(Request $request)
    $price = $request->get('price');

Then, remove all {budget} occurences .

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download