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
The pages class is extending the CI_Controller class. This means that the new pages class can access the methods and variables defined in the CI_Controller class ( system/core/Controller. php ). The controller is what will become the center of every request to your web application.
To actually answer your question, $this actually represents the singleton Codeigniter instance (which is actually the controller object). For example when you load libraries/models, you're attaching them to this instance so you can reference them as a property of this instance.
Class Constructors If you intend to use a constructor in any of your Controllers, you MUST place the following line of code in it: parent::__construct(); The reason this line is necessary is because your local constructor will be overriding the one in the parent controller class so we need to manually call it.
In CodeIgniter, hooks are events which can be called before and after the execution of a program. It allows executing a script with specific path in the CodeIgniter execution process without modifying the core files.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With