[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' (
`id` INT(10) NOT NULL AUTO_INCREMENT,
`category_id` int(12) unsigned NOT NULL REFERENCES categories(id),
`name` VARCHAR(255) NOT NULL,
`label` VARCHAR(255) NOT NULL,
`desc` LONGTEXT NULL,
`type` ENUM( 'textbox', 'textarea', 'dropdown', 'checkbox') NOT NULL,
....
....
`required` bool NOT NULL default 1,
`field_owner` VARCHAR(255) NOT NULL default '',
PRIMARY KEY id (`field_id`)
) TYPE=MyISAM;;
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){
if ($field['type']=textbox
$output .= $this->load->view('form_textbox', 'some data', true);
elseif ($field['type']=checkbox
$output .= $this->load->view('form_checkbox', 'some data', true);
elseif ......
else ......
}
However, I'm feeling that I'm writing unnecessary code and there must be a more elegant way to achieve this. Any help?