php - How to retrieve the third uri segment in a codeigniter hook -


i'm writing custom post_controller hook. know, codeigniter uri structure this:

example.com/class/function/id/ 

and code:

function hook_acl() {     global $rtr;     global $ci;      $controller = $rtr->class; // class part in uri     $method = $rtr->method; // function part in uri     $id = ? // how parse this?      // other codes omitted brevity } 

i've browsed core router.php file, puzzled me lot.

thanks.

using codeigniter uri core class

generally within codeigniter hooks, need load/instantiate uri core class reach methods.

  • for post_controller_constructor, post_controller, ... hooks, can codeigniter super object , use use uri class:
# ci instance $ci =& get_instance();  # third segment $ci->uri->segment(3); 
  • but pre_controller hook, don't have access codeigniter super object have load uri core class manually follows:
# load uri core class $uri =& load_class('uri', 'core');  # third segment $id = $uri->segment(3); // returns id 

using pure php

in approach can use $_server array fetch uri segments as:

$segments = explode('/', trim($_server['request_uri'], '/'));  $controller = $segments[1]; $method     = $segments[2]; $id         = $segments[3]; 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -