Hey guys, I am new to CodeIgniter and need some help. I have a controller that formats the content area of a post. The problem is that I also need to create a sidebar that contains dynamic groups, and a right column that contains recent posts. This isn’t hard, the problem I’m running into is that I want the sidebar, and right column on every page, and I don’t want to recode the same bits to get the data in every controller.
What would be the best way to do this without copy/paste?
There are a lot of ways to do this.
1) Templating: This is my preference for most cases (because my templates are complex), I render my view into a variable using something like:
Then I load it into the template parser (fyi you could load it into another view too) like this:
Then your template is like:
2) Load another view in your view: (assumes you menu is a view not a controller) Something like this:
3) PHP Includes: exactly how you would do it in plain PHP (just include a url which points to a controller which returns a menu), Something like this:
Codeigniter will render that page and then include it.
4) AJAX.. i use this if the content in the “template” content is less important, like banners, suggested related item lists and such.