Welcome Guest, Not a member yet? Register   Sign In
newbie in hopless mess with arrays and mvc,
#1

[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>
#2

[eluser]xwero[/eluser]
The data array isn't passed on to the view but is extracted by the keys.
Code:
// controller
$data['dropdown'] = $this->get_width->get_all();
// view
form_dropdown('width', $dropdown, '1');
#3

[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 :-)




Theme © iAndrew 2016 - Forum software by © MyBB