CodeIgniter Forums
Unlikely question... - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Development & Programming (
+--- Thread: Unlikely question... (/thread-39029.html)

Unlikely question... - El Forum - 02-27-2011

I am running codeigniter 2 with Smarty 3.

I am have my site menu running from a library which is called from the smarty file with the header in it.

I want to use the same library function for my admin area so that I can use the same header file. The admin uses a different controller though.

In CI is there a way of working out which controller I have run the page in?

So for example in my library I could put something like:

if(ci_controller == 'admin'){
show admin menu
show main menu

thanks... alternatively I guess this can be worked out with some php...

Unlikely question... - El Forum - 02-27-2011

If you have something like "" or "" in the url you can just grab the controller name using the URI Class:

if ($this->uri->segment(1) == 'admin')
    // load admin menu
    // load main menu

The URI class is ALWAYS autoloaded so you don't have to load anything to make this work Smile

I hope this solved your problem Wink

Unlikely question... - El Forum - 02-27-2011

private $CI;
private $controller;
private $method;

$this->controller = $this->CI->router->fetch_class();
$this->method     = $this->CI->router->fetch_method();


Unlikely question... - El Forum - 02-27-2011

Thanks AoiKage, your suggestion worked perfectly.