Вопрос

I use Kohana 3.3 help me, please, an example of route to the implementation of the Clean URL.

site.ru/param1/param2/param3/.../paramN/id

We have an unknown number of parameters, but the latter is always worth 'id' That is, There are different variants:

site.ru/param1/param2/param3/.../paramN/id
site.ru/param1/id
site.ru/id
Это было полезно?

Решение

Very well little grasshopper, here you have something to play:


Following route will take any amount of parameters (0..n). <id> represents a number:

Route::set('testparams', 'account(/<params>)/<id>',
    array(
        'params' => '.+',
        'id' => '\d+'))
    ->defaults(array(
        'controller' => 'account',
        'action'     => 'test',
));

The controller account and method test are like this:

class Controller_Account extends Controller {

    public function action_test()
    {
        $params = $this->request->param();
        echo Debug::vars($params);        

        $id = $this->request->param('id');
        echo Debug::vars($id);        

        exit;
    }

}

Testing 1:

http://localhost//account/p1/p2/p3/p4/p5/500

// result:
array(2) (
"params" => string(14) "p1/p2/p3/p4/p5"
"id" => string(3) "500"
)
string(3) "500"

Testing 2:

http://localhost/account/500

// result:    
array(2) (
"params" => string(0) ""
"id" => string(3) "500"
)
string(3) "500"
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top