Php 科哈纳3.2-路由问题

Php 科哈纳3.2-路由问题,php,regex,routes,kohana,kohana-3,Php,Regex,Routes,Kohana,Kohana 3,首先,Kohana的文档很糟糕,在人们开始“阅读文档”之前,我已经阅读了文档,它们似乎没有什么意义,甚至复制和粘贴一些代码对文档中的某些内容也不起作用 考虑到这一点,我有这样一条路线: //(enables the user to view the profile / photos / blog, default is profile) Route::set('profile', '<userid>(/<action>)(/)', array( // (/) for t

首先,Kohana的文档很糟糕,在人们开始“阅读文档”之前,我已经阅读了文档,它们似乎没有什么意义,甚至复制和粘贴一些代码对文档中的某些内容也不起作用

考虑到这一点,我有这样一条路线:

//(enables the user to view the  profile / photos / blog, default is profile)
Route::set('profile', '<userid>(/<action>)(/)', array( // (/) for trailing slash
    "userid" => "[a-zA-Z0-9_]+",
    "action" => "(photos|blog)"
))->defaults(array(
    'controller' => 'profile',
    'action' => 'view'
))
然后在控制器中执行以下操作:

public function action_index(){
    $method = $this->request->param('useraction');
    if ($method && method_exists($this, "action_{$method}")) {
        $this->{"action_{$method}"}();
    } else if ($method) {
    // redirect to remove erroneous method from url
    } else {
        $this->action_view(); // view profile
    }
}
(在
\uu construct()
函数中可能会更好,但您可以了解它的要点。)

不过,如果有更好的方法(确实应该有)的话,我宁愿不这样做

我认为答案可能在正则表达式中,但以下情况不起作用:

$profile_functions = "blog|images";
//(enables the user to view the images / blog)
Route::set('profile', '<id>/<action>(/)', array( 
            "id" => "[a-zA-Z0-9_]+",
            "action" => "($profile_functions)",
))->defaults(array(
    'controller' => 'profile'
));
Route::set('profile_2', '<id>(<useraction>)', array(
            "id" => "[a-zA-Z0-9_]+",
            "useraction" => "(?!({$profile_functions}))",
))->defaults(array(
    'controller' => 'profile',
    'action'     => 'view'
));
$profile_functions=“blog|images”;
//(使用户能够查看图像/博客)
路由::集合('profile','/(/)',数组(
“id”=>“[a-zA-Z0-9_200;]+”,
“操作”=>“($profile_函数)”,
))->默认值(数组)(
“控制器”=>“配置文件”
));
路由::集合('profile_2','()',数组(
“id”=>“[a-zA-Z0-9_200;]+”,
“useraction”=>“(?!({$profile_functions}))”,
))->默认值(数组)(
“控制器”=>“配置文件”,
“操作”=>“视图”
));

虽然当ID后面没有任何内容时它确实匹配。

我会像这样设置路线:

Route::set('profile', '<userid>(/<useraction>)(/)', array(
    "userid" => "[a-zA-Z0-9_]+",
    "useraction" => "(photos|blog)"
))->defaults(array(
    'controller' => 'profile',
    'action' => 'index'
))
Route::set('profile', '<userid>(/<action>)(/)', array(
    "userid" => "[a-zA-Z0-9_]+",
    "action" => "[a-zA-Z]+"
))->defaults(array(
    'controller' => 'profile',
    'action' => 'index'
))
或者类似的,只需验证控制器中的操作

编辑:

这也可以起作用:

if(!is_callable(array($this, 'action_' . $this->request->_action))){
    $this->request->_action = 'view';
}

我会这样设置路线:

Route::set('profile', '<userid>(/<useraction>)(/)', array(
    "userid" => "[a-zA-Z0-9_]+",
    "useraction" => "(photos|blog)"
))->defaults(array(
    'controller' => 'profile',
    'action' => 'index'
))
Route::set('profile', '<userid>(/<action>)(/)', array(
    "userid" => "[a-zA-Z0-9_]+",
    "action" => "[a-zA-Z]+"
))->defaults(array(
    'controller' => 'profile',
    'action' => 'index'
))
或者类似的,只需验证控制器中的操作

编辑:

这也可以起作用:

if(!is_callable(array($this, 'action_' . $this->request->_action))){
    $this->request->_action = 'view';
}

对不起,我不明白。返回什么?不要使用数组,但忽略我
在数组(“action”{$request->\u action}中,获取类方法($this))
对不起,我不明白。返回什么?不要使用数组,但忽略我<代码>在数组(“action”{$request->\u action}中,获取类方法($this))