MVC Organization: Multiple View Pieces in One 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: MVC Organization: Multiple View Pieces in One Controller (/showthread.php?tid=36101) |
MVC Organization: Multiple View Pieces in One Controller - El Forum - 11-21-2010 [eluser]Walter Coots[/eluser] I'm fairly new to MVC and even newer to Code Igniter, so please bear with me. Essentially what I'm doing is generating a form based on rows in a database. Each row represents a different input field, and also contains its label, a sorting column, and what fieldset to group the input into. In the past I've had a really large switch statement: Based on an integer (1 - 16), the field type is determined and the appropriate code is output via an echo(). I'm curious what the best practices are, since I can think of a few ways to tackle the problem: A: Store each input in a separate view, e.g. /application/views/formGenerator/inputFields/inputType1.php, and load using a switch statement B: Separate the entire switch statement into its own view, e.g. /application/views/formGenerator/inputGenerator.php C: Continue having the view echos in the switch statement within the controller's method D: Or maybe another way I'm not thinking of? It seems like option A would be less code on the whole, but more disorganized and potentially harder to read... thus defeating the purpose of MVC. Option B is the happy medium, and option C seems like it's an unnecessary amount of views but the most organized and possibly easiest to sort through later. What would you do? MVC Organization: Multiple View Pieces in One Controller - El Forum - 11-26-2010 [eluser]Walter Coots[/eluser] To whom it may concern: I went with option B and used the form helper rather than having a separate view for each input type. This was a lot less code with fewer files. |