CodeIgniter Forums

Full Version: MVC Organization: Multiple View Pieces in One Controller
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[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?

El Forum

[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.