簡體   English   中英

Symfony 1.4,我想對網址進行一些修改(路由?)如何?

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

所有鏈接都按我的預期工作,但是現在我必須創建一個自定義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/*

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM