简体   繁体   English

Symfony 1.4,我想对网址进行一些修改(路由?)如何?

[英]Symfony 1.4, I want a little modified url working (routing?) how?

All links works as I expect but now I have to make a custom URL. 所有链接都按我的预期工作,但是现在我必须创建一个自定义URL。 Let it be "userprofile/username" where the userprofile is the module name, while username is not an action but the user name. 使其为“ userprofile / username”,其中userprofile是模块名称,而username不是操作而是用户名。 A GET parameter, in other words. 换句话说,就是GET参数。 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. 可悲的是,我在该模块中创建了一个/config/routing.yml,似乎没有考虑到。

Your routing.yml file is global for the application, you can't specify a different one for a specific module. 您的routing.yml文件是应用程序的全局文件,您不能为特定模块指定其他文件。 This is because Symfony must find a matching route before it knows which module to use. 这是因为Symfony必须先找到匹配的路由,然后才能知道要使用哪个模块。

Try this in your apps/appname/config/routing.yml file: 在您的apps / appname / config / routing.yml文件中尝试以下操作:

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: 然后在您的apps / appname / modules / userprofile / actions / actions.class.php中执行以下操作:

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. 与往常一样,不要忘记在更改任何配置文件后运行symfony cc

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/*

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

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