Sharing a feature in more than one controller |
I have 3 controllers for different pages of product types.
In all this pages only the header area looks similar (images and text form a database, some price calculations). I don't want to create this area in all 3 controllers over and over again. How can i share this feature in all 3 controllers? In the MY_Controller it is always loaded (not only on product pages) and i think this is not so good. Is there another solution or best practise?
You can create multiple base controllers to achieve this. You should create a Products_base controller in the core directory then you should include that file at the beginning of every products related controller and extend that controller instead of CI_Controller or MY_Controller...
If you don't want to include that every time then you should create an spl_autoload method maybe in the front-controller (index.php in the root)!
Thank you. This works fine. I havn't done so much with CI and sometimes don't know what keywords to use for searching. But this forum is great.
Depending on how broad the feature is, I like to create a library and autoload the library. You can access the library in any controller that way.
|
Welcome Guest, Not a member yet? Register Sign In |