How to not repeat code in codeigniter? |
[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
[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.
|
Welcome Guest, Not a member yet? Register Sign In |