Codeigniter if controller

First of all, sorry if his question is noob.

But is it worth it to do in the encoder, for example, if I have a sidebar, but I want to load it only 2 pages.

if(controller == 'blog') {
   //load sidebar
}

same as wordpress if is_page

+5
source share
2 answers

Use $this->router->fetch_class()

if($this->router->fetch_class() == 'blog') {
   //load sidebar
}

It $this->uri->segment(2)will also work in most cases, but in some cases, for example, mod_rewriteeither during use subfolderor routeit may fail.

+5
source

More simply you can do it.

$controller_name = $this->CI->router->fetch_class();
if($controller_name === "your_controller_name")
{
 //your logic
}
0
source

All Articles