Welcome Guest, Not a member yet? Register   Sign In
What's the best way to control the output (view) based on database entry?
#1

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


Messages In This Thread
What's the best way to control the output (view) based on database entry? - by El Forum - 08-02-2010, 08:24 AM



Theme © iAndrew 2016 - Forum software by © MyBB