[英]passing data from controller to view in CodeIgniter results in Undefined variable
I have this function in my controller:我的 controller 中有这个 function:
public function checkout(){
$data['items'] = $this->cart_model->get_items();
$this->load->view("templates/header");
$this->load->view("cart/checkout", $data['items']);
}
Inside the checkout view I try to use this variable:在结帐视图中,我尝试使用此变量:
<?php foreach($items as $k => $item){?>
But this results in an error:但这会导致错误:
Message: Undefined variable: items消息:未定义的变量:项目
Any suggestions on how to fix this?对于如何解决这个问题,有任何的建议吗?
change this改变这个
$this->load->view("cart/checkout", $data['items']);
to this对此
$this->load->view("cart/checkout", $data);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.