Welcome Guest, Not a member yet? Register   Sign In
Unlikely question...

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...

If you have something like "www.yoursite.com/admin" or "www.yoursite.com/index.php/admin" 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

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

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


Thanks AoiKage, your suggestion worked perfectly.

Theme © iAndrew 2016 - Forum software by © MyBB