What's the best way to control the output (view) based on database entry? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: What's the best way to control the output (view) based on database entry? (/showthread.php?tid=32723) |
What's the best way to control the output (view) based on database entry? - El Forum - 08-02-2010 [eluser]dynZack[/eluser] Hi everyone, just learning CI and already excited about the speed of developing. This is probably easy: I have some custom fields that take user input. Each custom field is stored in: Code: CREATE TABLE 'fields' ( So I select all the fields that correspond to a certain category_id and generate a form. I want to be able to control the view based on the type of the fields (textbox, textarea, dropdown, checkbox). Basically I could do this in the controller: Code: foreach ($allfields as $field){ However, I'm feeling that I'm writing unnecessary code and there must be a more elegant way to achieve this. Any help? What's the best way to control the output (view) based on database entry? - El Forum - 08-02-2010 [eluser]clip[/eluser] You could do a helper function that accepts your data and return the expected form element using the form_helper. Something like this. Code: function form_magic($name, $type, $val, $attributes) Keep in mind you will still have to determine where you want to start and end your form. In the controller or in your view. Hope this helps. Edit: For this to work as I have shown, your enum values would have to corespond to the correcth form_helper functions. For example you would have to change the enum value of textbox to input. What's the best way to control the output (view) based on database entry? - El Forum - 08-03-2010 [eluser]dynZack[/eluser] Thanks for the help. Worked great! |