Reputation: 4152
I'm facing a little issue with the routing of Symfony.
This is my controller action:
/**
* @Route("/admin/pricelist/list/{year}/{week}", name="pricelist_list")
*/
public function getPricelistAction(Request $request, $year = 0, $week = 0)
{
$entityManager = $this->getDoctrine()->getManager();
if ($year === 0) {
$year = (int)date('Y');
}
if ($week === 0) {
$week = (int)date('W');
}
$start = new \DateTimeImmutable($year . '-1-1');
$stop = $start->modify('+1 year');
// ... I return the week and year to my twig
}
Now in my twig I have the following:
<div>
<div class="form-group">
<label>Year</label>
<select class="form-control" id="yearSelection">
{% for y in (year-3)..(year+3) %}
<option {% if y == year %}selected="selected"{% endif %}
data-url="{{ path('pricelist_list', {'year': y, 'week': week}) }}">
{{ y }}
</option>
{% endfor %}
</select>
</div>
<div class="form-group">
<label>Week</label>
<select class="form-control" id="weekSelection">
{% for key, w in weeks %}
<option {% if w == week %}selected="selected"{% endif %}
data-url="{{ url('pricelist_list', {'year': year, 'week': w}) }}">
{{ w }}
</option>
{% endfor %}
</select>
</div>
</div>
But when I select a year or a week, it doesn't lead me to the url admin/pricelist/list/{{year}}/{{week}}
as suggested in my routing, but to: admin/pricelist/list?year=2015&week=8
.
I really have no idea what I'm doing wrong, since other functions on other pages are working correctly with the routing in this way.
Can someone point me in the right direction?
Upvotes: 1
Views: 44
Reputation: 3523
Debug your routes with: php app/console router:debug
Then you will see that pricelist_list doesn't accept any parameters.
Possible reasons that popped into my mind:
Upvotes: 2