![]() |
Formatting of HTML: View or Controller - 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: Formatting of HTML: View or Controller (/showthread.php?tid=11846) |
Formatting of HTML: View or Controller - El Forum - 09-25-2008 [eluser]prezet[/eluser] Hi Just a general question, if I have an array of data, and I wanted out output this array in the form of an html unordered list as so: Code: $output = ''; Should this type of formatting be done in the controller, and passed to the view, or done directly in the view?? Cheers Formatting of HTML: View or Controller - El Forum - 09-25-2008 [eluser]xwero[/eluser] the html helper has a ul function for this sort of thing if you want to keep the view clean. If you think designers are going to change it you better loop it in the view. Formatting of HTML: View or Controller - El Forum - 09-25-2008 [eluser]prezet[/eluser] Is it better MVC practise to do this in the controller? Or is using the view acceptable? Formatting of HTML: View or Controller - El Forum - 09-25-2008 [eluser]Référencement Google[/eluser] I would say that when it's time to talk about HTML or user output, it's time to think of a view. That said, we all know it's not always possible to keep PHP 100% free of HTML code, sometimes it happend, but when you can avoid to have that situation, then do it. As for your example in your first post, I would do that in a view since it is user output related. Formatting of HTML: View or Controller - El Forum - 09-25-2008 [eluser]Dready[/eluser] As always data in the controller and html in the view... views/ul.php Code: <ul> controller : Code: $tpl = array ('items'=> array ( Formatting of HTML: View or Controller - El Forum - 09-25-2008 [eluser]Colin Williams[/eluser] I've yet to find much of any reason to put HTML in the controller. You can just load views in a loop and pass the results on to a broader view that contains the list of view outputs. |