Codeigniter 其显示变量未定义
这是我的控制器页面 公共职能指数() {Codeigniter 其显示变量未定义,codeigniter,Codeigniter,这是我的控制器页面 公共职能指数() { $getALlCat=$this->Product_model->getAllCategory(); $data=array(); //检索购物车数据 $data['cartItems']=$this->cart->contents(); //打印($data);退出; //$this->load->view('cart/index',$data); ///$this->load->helper('url'); //$this->load->view(
$getALlCat=$this->Product_model->getAllCategory();
$data=array();
//检索购物车数据
$data['cartItems']=$this->cart->contents();
//打印($data);退出;
//$this->load->view('cart/index',$data);
///$this->load->helper('url');
//$this->load->view('cart/header',['getAllCate'=>$getALlCat],$data);//包括header和
页脚
$this->load->view('cart/cartbody',['getAllCate'=>$getALlCat],$data);
$this->load->view('common/footer');//包括页眉和页脚
}
}
**这是查看页面**
“width=”50“/>
你是苏吗
你的车是空的
**像这样显示错误**
遇到一个PHP错误
严重性:通知
消息:未定义变量:cartItems
文件名:cart/cartbody.php
电话号码:217
回溯:
文件:C:\xampp\htdocs\shop\application\views\cart\cartbody.php
电话号码:217
函数:\u错误\u处理程序
文件:C:\xampp\htdocs\shop\application\controllers\Cart.php
电话号码:33
功能:查看
文件:C:\xampp\htdocs\shop\index.php
电话号码:315
功能:只需一次尝试以下操作
$this->load->view('cart/cartbody',['getAllCate'=>$getALlCat, 'cartItems'=> $this->cart->contents()]);
您可以将多个值存储为
$data
的数组键
,然后仅发送$data
以查看和使用这些键检索值。我已在下面更正了您的代码,它应该可以根据您的需要工作。我在必要时提到了注释
public function index() {
$data = array();
$data['getALlCate'] = $this->Product_model-> getAllCategory(); // store it in an array instead (I've changed it to getALlCate from getALlCat, so you don't have to change anything in your view)
//Retrieve cart Data
$data['cartItems'] = $this->cart->contents();
//$this->load->view('cart/header', $data); // including header and footer
$this->load->view('cart/cartbody', $data);
$this->load->view('common/footer'); //including header and footer
}
}
// you can retrieve data in view by accessing $cartItems and $getALlCate variables.
希望对你有帮助
$this->load->view('cart/cartbody',['getAllCate'=>$getALlCat, 'cartItems'=> $this->cart->contents()]);
public function index() {
$data = array();
$data['getALlCate'] = $this->Product_model-> getAllCategory(); // store it in an array instead (I've changed it to getALlCate from getALlCat, so you don't have to change anything in your view)
//Retrieve cart Data
$data['cartItems'] = $this->cart->contents();
//$this->load->view('cart/header', $data); // including header and footer
$this->load->view('cart/cartbody', $data);
$this->load->view('common/footer'); //including header and footer
}
}
// you can retrieve data in view by accessing $cartItems and $getALlCate variables.