这是我的模型-我想分配行并在视图页面上回显,例如<?php echo $product?>
class Model_products extends CI_Model {
function printer()
{
$id = $this->uri->segment(3, 0);
$q = $this->db->get_where('printer', array('id' => $id));
if ($q->num_rows == 1)
{
foreach ($q->result() as $row)
{
echo $row->name; # THIS WORKS
$data['product'] = $row->name; # THIS DOES NOT WORK
$data['desc'] = $row->description;
$data['size'] = $row->size;
$data['options'] = $row->options;
$data['more'] = $row->more_info;
}
}
}
}
这是我的控制器
public function products()
{
$this->load->model('Model_products');
$this->Model_products->printer();
$this->load->view('products', $data);
$this->load->view('pricing');
}
我的看法是
<h1>
<?php echo $product; ?>
</h1>
<p>
<?php echo $desc; ?>
</p>
<h3>
Size
</h3>
<p>
<?php echo $size; ?>
</p>
如何正确地将我的模型数组传递给我的控制器,以便我可以在我的视图中回显?