model
public function cart()
{
$this->load->model('Cart_model');
$this->load->view('head');
$data['pricing'] = $this->Cart_model->R_products();
$this->load->view('cart', $data);
$this->load->view('footer');
}
view
var_dump($data);
This produces error "
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: data
Filename: views/cart.php
Line Number: 4
"
However if I insert in my VIEW
$data = $this->Cart_model->R_products();
Then all is well. But why isn’t the controller doing it’s job?
model
class Cart_model extends CI_Model {
function R_products()
{
return $this->db->get('pricing')->result();
}
}
creates a variable called
$pricingthat you can use in your VIEW