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
}
精彩评论