简体   繁体   中英

Codeigniter if controller

First of all sorry if its a noob question.

But is it posibble to do this in codeingiter, like if i have a sidebar but i only want to load it in 2 pages

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

just like in wordpress if is_page

Use $this->router->fetch_class()

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

Also $this->uri->segment(2) will work in most cases, but in some cases like mod_rewrite or when using subfolder or route it may fail.

More simply you can do like this.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM