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
Use $this->router->fetch_class()
$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.
$this->uri->segment(2)
mod_rewrite
subfolder
route
More simply you can do it.
$controller_name = $this->CI->router->fetch_class(); if($controller_name === "your_controller_name") { //your logic }