Php symfony1.4,我想要一个小修改的url工作(路由?)如何?

Php symfony1.4,我想要一个小修改的url工作(路由?)如何?,php,url,symfony1,Php,Url,Symfony1,所有链接都像我期望的那样工作,但现在我必须创建一个自定义URL。 让它成为“userprofile/username” 其中,userprofile是模块名,而username不是操作,而是用户名。换句话说,是一个GET参数。如何创建这样的路由,并仅应用于此模块?遗憾的是,我在该模块中创建了一个/config/routing.yml,似乎没有被考虑。您的routing.yml文件是应用程序的全局文件,您不能为特定模块指定其他文件。这是因为Symfony必须先找到匹配的路由,然后才能知道要使用哪个

所有链接都像我期望的那样工作,但现在我必须创建一个自定义URL。 让它成为“userprofile/username”
其中,
userprofile
是模块名,而
username
不是操作,而是用户名。换句话说,是一个GET参数。如何创建这样的路由,并仅应用于此模块?遗憾的是,我在该模块中创建了一个/config/routing.yml,似乎没有被考虑。

您的routing.yml文件是应用程序的全局文件,您不能为特定模块指定其他文件。这是因为Symfony必须先找到匹配的路由,然后才能知道要使用哪个模块

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

然后在您的apps/appname/modules/userprofile/actions/actions.class.php中有一个如下操作:

public function executeShowUser(sfWebRequest $request) {
  $username = $request->getParameter('username');
  //do something!
}

和往常一样,在更改任何配置文件后,不要忘记运行symfony cc。

您的routing.yml文件是应用程序的全局文件,您不能为特定模块指定其他文件。这是因为Symfony必须先找到匹配的路由,然后才能知道要使用哪个模块

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

然后在您的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/*

因此,要成为一个有价值的话题:

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

尝试使用dev环境在浏览器中浏览项目,以从symfony获取更多有用的错误消息。这通常类似于前端_dev.php(或appname_dev.php),然后是url的其余部分(例如localhost/frontend_dev.php/userprofile/zzzrByte我猜您会得到一个错误,showUserSuccess.php不存在。在apps/appname/modules/userprofile/templates/showUserSuccess.phpIf/userprofile/name.html中创建它会正确地转换为route/userprofile/:username.html…但是/userprofile/name不会转换为r。)oute/userprofile/:用户名超出服务器配置可能出现的问题。是否出现Symfony错误?是否尝试使用frontend_dev.php查看更详细的错误?是否可能在该错误上方有默认路由规则?尝试将用户_配置文件的路由规则放置在routing.yml和n再次运行symfony cc。如果这不起作用,请向我显示您的routing.yml文件。您的其余路由是否依赖默认的symfony路由规则?在我看来,对所有规则回退到/:module/:action是非常糟糕的做法……最好明确定义每个规则,因为它会给您带来更大的灵活性,而且您会错过了路由系统的整个要点。您应该真正阅读文档:-当我阅读这些评论时,您不知道SF1路由是如何工作的。顺便说一下,zzzrByte答案是正确的。请尝试使用开发环境在浏览器中浏览您的项目,以从symfony获得更多有用的错误消息。这通常是使用类似frontend_dev.php(或appname_dev.php)的东西,然后使用url的其余部分(例如localhost/frontend_dev.php/userprofile/zzzrByte我猜您会得到一个错误,showUserSuccess.php不存在。在apps/appname/modules/userprofile/templates/showUserSuccess.phpIf/userprofile/name.html中创建它会正确地转换为route/userprofile/:username.html…但是/userprofile/name不会转换为r。)oute/userprofile/:用户名超出服务器配置可能出现的问题。是否出现Symfony错误?是否尝试使用frontend_dev.php查看更详细的错误?是否可能在该错误上方有默认路由规则?尝试将用户_配置文件的路由规则放置在routing.yml和n再次运行symfony cc。如果这不起作用,请向我显示您的routing.yml文件。您的其余路由是否依赖默认的symfony路由规则?在我看来,对所有规则回退到/:module/:action是非常糟糕的做法……最好明确定义每个规则,因为它会给您带来更大的灵活性,而且您会您应该认真阅读文档:-当我阅读这些评论时,您不知道SF1路由是如何工作的。顺便说一句,ZZRBYTE答案是正确的。