All links works as I expect but now I have to make a custom URL. Let it be "userprofile/username" where the userprofile
is the module name, while username
is not an action but the user name. A GET parameter, in other words. How to create a routing like that, and apply to this module only? Sadly I created a /config/routing.yml into that module, and not seems to be taken account.
Your routing.yml file is global for the application, you can't specify a different one for a specific module. This is because Symfony must find a matching route before it knows which module to use.
Try this in your apps/appname/config/routing.yml file:
user_profile:
url: /userprofile/:username
param: { module: userprofile, action: showUser }
Then in your apps/appname/modules/userprofile/actions/actions.class.php have an action like this:
public function executeShowUser(sfWebRequest $request) {
$username = $request->getParameter('username');
//do something!
}
And as always, don't forget to run symfony cc after changing any config file.
so, to be a valuable topic:
# 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/*
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.