如何在 CodeIgniter 中的钩子中访问路由系统提供给控制器的参数


How to access the params given to the controllers by the routing system within a hook in CodeIgniter?

我想使用 post_controller_constructor 挂钩记录我的应用程序收到的请求。

下面的钩子代码说明了我需要什么:

public function log() {
  $controller = $this->router->fetch_class();
  $action = $this->router->fetch_method();
  $post_params = $this->input->post();
  $get_params = $this->input->get();
  $url_params = ???;
...
  $this->log_model->log($id_user, $controller, $action, time(), $post_params, $get_params, $url_params);
}
function __get($key){
  $CI =& get_instance();
  return $CI->$key;
}

对于我所看到的,解决方案必须与"URI"类和从那里提取的段相关。但是我不能依赖这个 aproach,因为我发现某些控制器比其他控制器更深,如以下示例:


  • /folder/set_controllers/controller_a/action/(:any) /folder/set_controllers/controller_a/action/7 $url_params的值为 array('7')

  • /folder/controller_b/action/(:any)/(:any) /folder/controller_b/action/first_param/second_param/7 $url_params的值为 array('first_param', 'second_param')

  • /controller_c/action/(:any) /controller_c/action/hello $url_params的值为 array('hello')

我需要知道$url_params有什么价值观。

提前谢谢。

也许这个问题的答案可以帮助你 如何使用CodeIgniter获取控制器,操作,URL信息 看起来您正在寻找相同,或多或少。