Symfony 的路由问题
Issue with Symfony's routing
我在 Symfony 的路由方面遇到了一个小问题。
这是我的控制器操作:
/**
* @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
}
现在我的树枝中有以下内容:
<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>
但是当我 select 一年或一周时,它并没有按照我的路线建议将我带到 url admin/pricelist/list/{{year}}/{{week}}
,而是: admin/pricelist/list?year=2015&week=8
.
我真的不知道我做错了什么,因为其他页面上的其他功能以这种方式与路由一起正常工作。
有人能指出我正确的方向吗?
调试你的路由:php app/console router:debug
然后你会看到pricelist_list不接受任何参数。
我想到的可能原因:
- 您正在使用 YAML 配置方法,您的 @Route 注释被忽略
- 您正在编辑的控制器不是被加载的控制器(例如另一个文件夹中的备份)
我在 Symfony 的路由方面遇到了一个小问题。
这是我的控制器操作:
/**
* @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
}
现在我的树枝中有以下内容:
<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>
但是当我 select 一年或一周时,它并没有按照我的路线建议将我带到 url admin/pricelist/list/{{year}}/{{week}}
,而是: admin/pricelist/list?year=2015&week=8
.
我真的不知道我做错了什么,因为其他页面上的其他功能以这种方式与路由一起正常工作。
有人能指出我正确的方向吗?
调试你的路由:php app/console router:debug
然后你会看到pricelist_list不接受任何参数。
我想到的可能原因:
- 您正在使用 YAML 配置方法,您的 @Route 注释被忽略
- 您正在编辑的控制器不是被加载的控制器(例如另一个文件夹中的备份)