Вопрос

For example:

mysite.com/questions/test/1

And I want to know if it's realy contains a string test with id which is 1 in this example.

Note. It's not a standart controller vs action and id. I must to check this and set the route(controller vs. action) for this.

add. The reason is this part mysite.com/["questions/"]test/1 can contain any amount of words, like mysite.com/a/b/c/d/test/1, but the end of the url is always test/(id).

Это было полезно?

Решение

You can modify the regular expression for each part of the route and thus allow additional /. Your route could look like this:

Route::set('test', '<question>/test/<id>',
    array(
        'question' => '[^.,;?\n]+',
        'id' => '\d+',
    ))
    ->defaults(array(
        'controller' => 'Test',
        'action'     => 'index',
    ));

<...> evaluates to [^/.,;?\n]++ - so remove the slash (since you want to allow it) and the additional plus and you have the one you looked for.

The URI /foo/bar/hello/test/5 will now be caught and you'll get the parameters

Array
(
    [question] => foo/bar/hello
    [id] => 5
)

accessible via $this->request->param()

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top