2013-02-26 182 views
1

我正在使用yaf php框架php mvc更改默認url模式

我想獲得參數數組。 例如:

我的網址:... mvcSample/SVC/saveUser/USER1 /通行證/ A @ BC /喬/富

我的輸出PARAMS轉儲:

array (size=3) 
    'user1' => string 'pass' (length=4) 
    '[email protected]' => string 'joe' (length=3) 
    'foo' => null 

我想:

array (size=5) 
1 =>string 'user1' 
2 => string 'pass' 
3 => string '[email protected]' 
4 => string 'joe' 
5 =>string 'foo' 

如何更改默認的網址格式?

謝謝

+0

'a @ bc'不是有效的網址。這會拋出各種錯誤。 你至少應該使用'a%40b.c' – Tschallacka 2013-02-26 08:43:28

回答

0

由於YAF是很好的無證,我能想到的唯一的選擇是由你自己來解析URI:

$parts = explode('/', $this->getRequest()->getRequestUri()); 

,但你會得到的$部分陣列begining垃圾。

Propably,遲早你會開始嘗試自定義URL路由(一些樣品,您可以在這裏找到:http://docs.php.net/manual/da/yaf-route-regex.construct.php),這將讓你解析使用正則表達式的網址,並通過匹配組控制器:

/* in Bootstrap.php */ 

$dispatcher->getRouter()->addRoute('saveUser', 
    new Yaf_Route_Regex(
     ',^/mvcSample/svc/saveUser/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)$,', 
     array(
      'controller' => 'svc', 
      'action' => 'saveUser', 
     ), 
     array(
      1 => 'username', 
      2 => 'password', 
      3 => 'email', 
      4 => 'firstname', 
      5 => 'somefooshmoo', 
     ), 
    ) 
);