When to use a library within the view (maybe?) - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: When to use a library within the view (maybe?) (/showthread.php?tid=40849) |
When to use a library within the view (maybe?) - El Forum - 04-20-2011 [eluser]c77m[/eluser] I know in an ideal world libraries would not be used inside a view. However, it is also ideal not to have redundant code all over the place, too. So what is the best answer to this conundrum? I have database-driven data that needs to be loaded on <b>EVERY</b> page in the site, regardless of controller and method. It is in a portion of a sidebar view, which is loaded on each page. Instead of loading the data in every single controller and passing it to the view, would this not be a good example of when you <i>should</i> access a library inside the view? I'm looking for pros and cons with a focus on code efficiency. When to use a library within the view (maybe?) - El Forum - 04-20-2011 [eluser]Eric Barnes[/eluser] From the way you describe it I would be using a helper instead of a library. When to use a library within the view (maybe?) - El Forum - 04-20-2011 [eluser]toopay[/eluser] I'll probably configure some hook for that! When to use a library within the view (maybe?) - El Forum - 04-20-2011 [eluser]John_Betong_002[/eluser] I sort-of solved a similar problem by calling a model function from the common MY_Controller->constructor(). The array loaded from the model function is passed to the sidebar view like this: Code: // MY_Controller edit: Unfortunately; introducing database caching has opened up a whole can of worms and the bl**dy list does not get updated |