CodeIgniter Forums
How to not repeat code in codeigniter? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: How to not repeat code in codeigniter? (/thread-33678.html)



How to not repeat code in codeigniter? - El Forum - 09-04-2010

[eluser]MWebber[/eluser]
Hi,
I'm new with CodeIgniter. I want to ask what is the best way to "autoload" some code needed for template, like meta tags and block generation for the main page using the database.I've read that it's best to use helpers or plugins, but does it normal to use them to connect to model or database? Any suggestions?

Nikolai


How to not repeat code in codeigniter? - El Forum - 09-04-2010

[eluser]WanWizard[/eluser]
Use a template library so you can build your page using partials, then use the MY_Controller constructor to generate the 'static' sections of your pages, like headers, footers, sidebar, etc.
If needed, you can use models to fetch information for these sections.

This way your controller method only needs to generate the body section of the template. It keeps your code clean.

You can also use multiple parent controllers. Phil Sturgeon wrote a great article about this.


How to not repeat code in codeigniter? - El Forum - 09-04-2010

[eluser]MWebber[/eluser]
Hi,
Thank you very much for your reply,

Nikolai