小花路由.可以包含字母但必须以数字结尾的 ID


Kohana routing. ID that can contain letters but must end with digit

我希望这条路线能够正常工作

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 

我试过了

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
));

但它是错误的,因为id现在只能包含字母

路由应该是特定的。不要试图使用一条路线来独占所有东西。这些将做你想做的事。

Route::set('forum/rules', 'forum/rules')
->defaults(array(
    'controller' => 'forum',
    'action' => 'rules',
));
Route::set('forum', 'forum/(<name>.)<id>(/<action>)',
 array(
    'action' => 'edit', // the action must not be present (and default to 'index') or be 'edit'
    'name' => ''w+',
   'id' => ''d+',
))
->defaults(array(
    'controller' => 'forum',
));

此外,仅当您重载某些内容并替换它时,才向操作和控制器的正则表达式添加-。PHP 类和函数/方法名称不允许包含短划线。

这解决了我的问题

'id' => '('w+.)?'d+'