![]() |
newbie in hopless mess with arrays and mvc, - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: newbie in hopless mess with arrays and mvc, (/showthread.php?tid=6910) |
newbie in hopless mess with arrays and mvc, - El Forum - 03-17-2008 [eluser]ciPhil[/eluser] Hi, I am still trying to learn and am stuck with this problem. I can solve it by running all the code from within the controller but I need to get the idea of passing the data around to use mvc. I think my problem is in the use of arrays in passing the data, the code is below, or then again maybe its some other misunderstanding, a lot of this code is from David Upton,s book. Can anyone help with a simple explanation of my errors, Thanks Phil <?php class Width extends Controller { function index() { parent::Controller(); $this->load->helper('url'); $this->load->helper('form'); $this->load->library('table'); $this->load->database(); $this->output->enable_profiler(TRUE); $this->load->model('get_width'); $data = $this->get_width->get_all(); $this->load->view('drop_form_view',$data); } } ?> MODEL <?php class Get_width extends Model { function Get_width() { parent::Model(); } function get_all() { $width_array = array(); $this->db->select('id, width'); $query = $this->db->get('tyre_width'); if ($query->num_rows() >0) { foreach ($query->result() as $row) { $width_array[$row->id] = $row->width; } } return $width_array; } } ?> VIEW <head> <body> <?php echo form_dropdown('width', $data, '1'); ?> </body> </head> newbie in hopless mess with arrays and mvc, - El Forum - 03-17-2008 [eluser]xwero[/eluser] The data array isn't passed on to the view but is extracted by the keys. Code: // controller newbie in hopless mess with arrays and mvc, - El Forum - 03-17-2008 [eluser]ciPhil[/eluser] xwero very many thanks for that, I would be embarrassed to tell you how long I have struggled with that.! cheers Phil :-) |