Hello, I have a controller with an index function as follows:
function index()
{
$this->load->model('products_model');
$data['product'] = $this->products_model->get(3); // 3 = product id
$data['product_no'] = 3;
$data['main_content'] = 'product_view';
//print_r($data['products']);
$this->load->view('includes/template', $data);
}
This is the get function in the products_model file
function get($id)
{
$results = $this->db->get_where('products', array('id' => $id))->result();
//get the first item
$result = $results[0];
return $result;
}
The products table contains fields such as name, price etc. Please can you tell me how to output variables from $data['product'] after it is passed into the view? I have tried so many things but nothing is working, even though the print_r (commented out) shows the data - it is not being passed into the view. I thought it may have been because the view calls a template file which references the main_content variable:
Template file contents:
<?php $this->load->view('includes/header'); ?>
<?php $this->load->view($main_content); ?>
<?php $this->load->view('includes/footer'); ?>
but i tried creating a flat view file and still couldn't access the variables.
Many thanks,