带有参数 url 创建的 symfony2 树枝路径 [英] symfony2 twig path with parameter url creation

查看:31
本文介绍了带有参数 url 创建的 symfony2 树枝路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了以下内容:

<a href="{{ path('_be_activatecategory', {'id': category.id, 'active': 1}) }}">Aktivieren</a>

创造

/backend/categories/activate/8/1

/backend/categories/activate/8/1

然后我得到了

<a href="{{ path('_category', {'id': category.id}) }}">

创建

/category?id=1

/category?id=1

看到区别了吗?我想要的是第二种情况与第一种情况完全一样:

see the difference? what i want is in the second case exactly like in the first:

/category/1

/category/1

我该如何管理?为什么 path() 助手没有为我创建带有参数的正确 url?

how can i manage this? why didnt the path() helper creates the correct url with parameters for me?

我的路由看起来像这样:

my routing looks like this:

/**
 * @Route("/category/{id}", name="_category")
 * @Template()
 */
public function categoryAction($id)
{

推荐答案

为路由中的 active 参数设置默认值.

Set the default value for the active argument in the route.

这篇关于带有参数 url 创建的 symfony2 树枝路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆