php mvc change default url pattern

593 Views Asked by At

I'm using yaf php framework

I want to get param array. ex:

My url:... mvcSample/svc/saveUser/user1/pass/[email protected]/joe/foo

My output params dump:

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

I want:

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

How to change default url pattern ?

Thank you

1

There are 1 best solutions below

0
On

Since Yaf is very well undocumented, the only option I can think about is to parse URI by Your own:

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

But You will get garbage on begining of $parts array.

Propably, sooner or later You will start to trying custom URL routing (some samples You can find here: http://docs.php.net/manual/da/yaf-route-regex.construct.php), which will allow You to parse URLs using regexps and pass matched groups to controller:

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