Welcome Guest, Not a member yet? Register   Sign In
How to get name of current class and function?
#1

[eluser]Unknown[/eluser]
I started using CodeIgniter a week ago and this is my first post, so greetings all!

What I want to do:
For every function within a controller, I'd like to be able to access the name of the controller, the name of the function and the URI segments.

What my current solution is:

//In codeigniter/Codeigniter.php, I initialized the controller class with the desired parameters. So instead of:
$CI=new $class();

//I have:
$CI=new $class($method,$URI->rsegments);

//END of Codeigniter.php

//In controllers/some_class.php, I receive the new parameters in the constructor, declare them as class variables, then get the class variables within each of the class' methods.
class Some_class{
protected $method;
protected $uri_rsegments;
function Some_class($method,$uri_rsegments)
{
$this->method=$method;
$this->uri_rsegments=$uri_rsegments;
}

function index()
{
$method=$this->$method
$uri_rsegments=$this->uri_rsegments;
}

function another_method()
{
$method=$this->$method
$uri_rsegments=$this->uri_rsegments;
}
}
//END OF some_class.php

What I would like help on:

A suggestion for a better, more rigorous, less invasive approach to accomplishing this than the "hack" I did. Hooks? config.php? $GLOBALS? $_SESSION? Which of these would work (and if you have time, why not)?

For the curious - what do I want this for?
- Have my anchor links update themselves relatively when I decide to reroute my URI's and omit the class from the URI.
- Log activity (the uri segments used) in my DB when a page is being visited.

Thanks!

-Adrian


Messages In This Thread
How to get name of current class and function? - by El Forum - 09-08-2008, 01:40 PM
How to get name of current class and function? - by El Forum - 09-08-2008, 02:09 PM
How to get name of current class and function? - by El Forum - 09-08-2008, 03:50 PM
How to get name of current class and function? - by El Forum - 09-08-2008, 04:00 PM
How to get name of current class and function? - by El Forum - 09-08-2008, 04:24 PM
How to get name of current class and function? - by El Forum - 09-08-2008, 04:48 PM
How to get name of current class and function? - by El Forum - 09-09-2008, 12:32 AM
How to get name of current class and function? - by El Forum - 04-22-2009, 11:18 AM
How to get name of current class and function? - by El Forum - 04-22-2009, 11:24 AM



Theme © iAndrew 2016 - Forum software by © MyBB