繁体   English   中英

如何在symfony中为带有多个参数的URL设置路由?

[英]how to set routing for the url with multiple parameters in symfony?

我正在使用symfony 1.0,并为以下几个URL设置了路由。

static_pages:
url: docs/:page.htm
param: { module: docs, action: index }

现在,我为另一种URL设置了路由。

URL is http://news4u.com/search/description/id/3/css/a/act/a

我将路由设置如下

description:
url: /search/description/id/:id/css/:manu/act/:mgh
param: { module: search, action: description}

这是获取'css'和'act'值的正确格式吗? 在URL缺少css参数时,我的意思是url如下:

http://news4u.com/search/description/id/3/css//act/a

-getRequestParameter('css')的值显示为'act',而-getRequestParameter('act')的值为空

因此,我尝试应用路由,如果有误,请更正我。 我不希望使用上面的路由配置。

除非您要在URL中使用它们的存在来将用户发送到搜索模块和描述操作,否则不必在您的routing.yml文件中指定“ id”,“ css”和“ act”作为参数。

在routing.yml中使用以下规则仍然有效:

default:
  url:   /:module/:action/*

那你应该可以使用

url_for('search/description', array(
   'id' => 4, 
   'css' => 'something', 
   'act' => 'blah'
); 

生成这样的链接:/ search / description / id / 4 / css / something / act / blah

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM