![]() |
How to add same content on many page - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: How to add same content on many page (/showthread.php?tid=13059) |
How to add same content on many page - El Forum - 11-09-2008 [eluser]dimethroxy[/eluser] Ok, let's say I have a website with a box containing the "last 10 comments". I want this box to display on different pages (controller) but not on every page. I don't want to repeat the code for this box in every controller. Is there a way to do this? I've searched and found the "Modular Extensions - HMVC" but is this the best solution to my problem ? Thanks and sorry for my English. How to add same content on many page - El Forum - 11-09-2008 [eluser]Pascal Kriete[/eluser] Hey dimethroxy, The native way of doing this is to use libraries, helpers, and models. A combination of those can do the job 99% of the time. In this case it's probably easiest to have a model that contains the query, and then use a a helper (or view) to format it as you like. So in the page views you just have: Code: <?= last_ten_comments() ?> Welcome to CodeIgniter. How to add same content on many page - El Forum - 11-09-2008 [eluser]ray73864[/eluser] turn it into a library and have the library autoloaded, then for each page you want to have it on just call the library function (eg. $this->comments->last_10()) inparo beat me to it.... I should really learn to refresh the page if it has been open for a while before posting ![]() How to add same content on many page - El Forum - 11-09-2008 [eluser]dimethroxy[/eluser] Thanks for your reply! After reading the library docs, it seem like my best choice is to create a library that will load my data model and then call the correct view and return the result. Then I will call this library from my view. Is this correct ? How to add same content on many page - El Forum - 11-09-2008 [eluser]Pascal Kriete[/eluser] @ray, I did the same thing less than 5 minutes later @dimethroxy, sounds good to me ![]() How to add same content on many page - El Forum - 11-10-2008 [eluser]dimethroxy[/eluser] Mmm... stupid questions but how do i load a model from a helper ? How to add same content on many page - El Forum - 11-10-2008 [eluser]Colin Williams[/eluser] Code: function helper_function() |