D
D
Dmitry Sergeev2013-09-17 08:08:37
Kohana
Dmitry Sergeev, 2013-09-17 08:08:37

How to specify in routing that id can contain letters but must necessarily end with a number?

The following paths need to work:
forum/forum-name.9 -> controller = forum, action = index, id = forum-name.9
forum/forum-name.9/edit -> controller = forum, action = edit, id = forum-name.9
forum/rules -> controller = forum, action = rules, id = null

I try like this

Route::set('default', '(/<controller>)((/<id>)(/<action>)))', 
     array(
        'controller' => '[a-zA-Z_-]+',
  'action' => '[a-zA-Z_-]+',
  'id' => '[a-zA-Zа-я0-9.-]+',
))
    ->defaults(array(
        'controller' => 'forum',
        'action' => 'index',
        'id'=>null
  ));


But of course it doesn't work properly.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Sergeev, 2013-09-18
@JetMaster

And it's even better to do

Route::set('default', '(/<controller>)((/(<name>.)<id>)(/<action>)))', 
     array(
        'controller' => '[a-zA-Z_]+',
        'action' => '[a-zA-Z_]+',
        'name' => '[a-zA-Zа-я0-9-]+',
        'id' => '\d+',

))
    ->defaults(array(
        'controller' => 'forum',
        'action' => 'index',
        'name'=>null,
        'id'=>0
  ));

D
DeVitoz, 2013-09-17
@DeVitoz

Through the regular expression /^\w+\d+$/ This is true syntax for js, I don’t know how in php. If anything, the regex itself between the slashes /<here>/ :--)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question