php mvc更改默认网址格式

时间:2013-02-26 08:01:01

标签: php url-routing yaf

我正在使用yaf php framework

我想得到param数组。 例如:

我的网址:... mvcSample/svc/saveUser/user1/pass/a@b.c/joe/foo

我的输出参数转储:

  array (size=3)
  'user1' => string 'pass' (length=4)
  'a@b.c' => string 'joe' (length=3)
  'foo' => null

我想:

array (size=5)
1 =>string 'user1'
2 => string 'pass' 
3 => string 'a@b.c'
4 => string 'joe' 
5 =>string 'foo'

如何更改默认网址格式?

谢谢

1 个答案:

答案 0 :(得分:0)

由于Yaf非常好,因此我能想到的唯一选择是自己解析URI:

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

但是你会在$ parts数组开始时得到垃圾。

可能,迟早您将开始尝试自定义URL路由(您可以在此处找到一些示例:http://docs.php.net/manual/da/yaf-route-regex.construct.php),这将允许您使用regexps解析URL并将匹配的组传递给控制器​​:

/* 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',
        ),
    )
);