I'm writing a custom post_controller hook. As we know, codeigniter uri structure is like this:
example.com/class/function/id/
and my code:
function hook_acl()
{
global $RTR;
global $CI;
$controller = $RTR->class; // the class part in uri
$method = $RTR->method; // the function part in uri
$id = ? // how to parse this?
// other codes omitted for brevity
}
I've browsed the core Router.php file, which puzzled me a lot.
thanks.
You can use the
router
class :Or the URI class :
Using CodeIgniter URI core class
Generally within CodeIgniter Hooks, we need to load/instantiate the URI core class to reach the methods.
post_controller_constructor
,post_controller
, ... hooks, we can get the CodeIgniter super object and use use theuri
class:pre_controller
hook, we don't have access to CodeIgniter super object So we have to load the URI core class manually as follows:Using pure PHP
In this approach you can use
$_SERVER
array to fetch the URI segments as: