Welcome Guest, Not a member yet? Register   Sign In
form dropdown problem. separate logic and presentation
#1

[eluser]Unknown[/eluser]
codeIgniter form_dropdown() function can receive only associative array but I have multi dimension array by using result_array() function. How can I fetch my data on form_dropdown() function?
I can solve this only view page. for example
Code:
$query = $this->db->query("SELECT id, item_name FROM items");

$options = array();

foreach ($query->result_array() as $row){
   $options[$row['id']] = $row['item_name'];
}

echo form_dropdown('my_items_dropdown', $options, '1');



But my query is not stay on model. If I want to separate logic and presentation. how can I build model function and how can I show my view page
#2

[eluser]TheFuzzy0ne[/eluser]
Welcome to the CodeIgniter forums!

I'm not quite sure why you are having problems. You put the logic you have to build your dropdown array into a model method, call the model method from your controller, and then pass the data into the view. It's up to you to decide the name of the model.




Theme © iAndrew 2016 - Forum software by © MyBB