Best Practice...where to generate a table |
[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)
[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.
[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.
[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();
|
Welcome Guest, Not a member yet? Register Sign In |