1

I want to log the requests that my app receive using a post_controller_constructor hook.

The hook's code below illustrate what I need:

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

For what I saw, the solution has to be related with 'URI' Class and the segments extracted from there. But I cannot rely on this aproach because I have that some controllers are deeper than others like this examples:

  • /folder/set_controllers/controller_a/action/(:any)
    /folder/set_controllers/controller_a/action/7 the value for $url_params is array('7').
  • /folder/controller_b/action/(:any)/(:any)
    /folder/controller_b/action/first_param/second_param/7 the value for $url_params is array('first_param', 'second_param').
  • /controller_c/action/(:any)
    /controller_c/action/hello the value for $url_params is array('hello').

And I need to know what values $url_params have.

Thanks in advance.

sanrodari
  • 1,602
  • 2
  • 13
  • 23

1 Answers1

3

Maybe the answer of this question can help you How to get Controller, Action, URL informations with CodeIgniter it looks you are looking for the same, more or less.

Community
  • 1
  • 1
jonaypelluz
  • 368
  • 4
  • 13