CodeIgniter Forums
Display content in table - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Display content in table (/thread-54356.html)



Display content in table - El Forum - 09-05-2012

[eluser]Diegosf93[/eluser]
Hello, i have a doubt i get info at the db and i want to format it in a table in the view archive but i´m not convinced at the idea of put php code in the view, exists another way to do this?


Display content in table - El Forum - 09-05-2012

[eluser]TWP Marketing[/eluser]
Do your formatting in a model, or in the controller and only send the formatted data to the view.
However, sometimes you must put php processing in a view, for instance a foreach() loop to write a list or html table. The code police will not be overly upset with this, because they do it themselves, sometimes...


Display content in table - El Forum - 09-05-2012

[eluser]Diegosf93[/eluser]
Thanks for your fast reply!


Display content in table - El Forum - 09-05-2012

[eluser]PhilTem[/eluser]
As by design: How you present your data should be handled in the view. Therefore you need to use PHP to create your table (i.e. loop over the results and format them how you want it) in the view.

Grab the data in the controller by calling the model and send the data (probably an array of arrays or objects) to the view which will make a table, an ul/ol or something else out of it Wink