Best Practice...where to generate a table - 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: Best Practice...where to generate a table (/showthread.php?tid=12289) |
Best Practice...where to generate a table - El Forum - 10-13-2008 [eluser]blasto333[/eluser] In a program I am writing, I have a module for adding, updating, deleting, and viewing customers. In my customer model, I created a function get_manage_table, that creates an html table and returns as a string. The result of this function is then passed into a view from my controller and outputted. Is this the way to go? Code: function get_manage_table($customers) Best Practice...where to generate a table - El Forum - 10-13-2008 [eluser]Colin Williams[/eluser] Your model is generating HTML, which is never a good thing in my book. I would relegate this to a helper with a function name like customer_table_form() if it must be abstracted. Best Practice...where to generate a table - El Forum - 10-13-2008 [eluser]blasto333[/eluser] That makes sense, thanks Best Practice...where to generate a table - El Forum - 10-13-2008 [eluser]blasto333[/eluser] When I started to go do this I realized that I cannot put this function in a helper because it needs access to the language and table libraries. I was thinking of moving the logic to the view, but this function is also used for AJAX. A user can do a search and the table is sent back and updated using the dom (really easy with jquery). So the only place I could move it to is the controller. If you want to see this in action go to: http://muench.homeip.net/phppointofsale/index.php/login username:admin password:pointofsale Click "Customers" at the top. I am trying to follow best practices and this did not feel like a good practice. Best Practice...where to generate a table - El Forum - 10-13-2008 [eluser]Pascal Kriete[/eluser] You can still put it in a helper (wohoo). You just need to grab an instance of the current CI super object: Code: $CI =& get_instance(); Best Practice...where to generate a table - El Forum - 10-13-2008 [eluser]blasto333[/eluser] cool, thanks! |