所有链接都能正常工作,但现在我必须创建一个自定义URL。设为"userprofile/username"其中userprofile
是模块名称,而username
不是动作而是用户名。换句话说,GET参数。如何创建这样的路由,并仅应用于此模块?遗憾的是,我在该模块中创建了/config/routing.yml,但似乎没有被考虑在内。
您的routing.yml文件是应用程序的全局文件,您不能为特定模块指定不同的文件。这是因为Symfony必须找到一条匹配的路由,才能知道要使用哪个模块。
请在apps/appname/config/routing.yml文件中尝试此操作:
user_profile:
url: /userprofile/:username
param: { module: userprofile, action: showUser }
然后在您的apps/appname/modules/userprofile/actions/actions.class.php中有这样的操作:
public function executeShowUser(sfWebRequest $request) {
$username = $request->getParameter('username');
//do something!
}
和往常一样,不要忘记在更改任何配置文件后运行symfony cc。
因此,成为一个有价值的主题:
# You can find more information about this file on the symfony website:
# http://www.symfony-project.org/reference/1_4/en/10-Routing
user_profile:
url: /userprofile/:username
param: { module: userprofile, action: showUser }
# default rules
homepage:
url: /
param: { module: index, action: index }
# generic rules
# please, remove them by adding more specific rules
default_index:
url: /:module
param: { action: index }
default:
url: /:module/:action/*