【发布时间】:2020-05-15 10:42:37
【问题描述】:
这是我的控制器页面
class Cart extends CI_Controller{
公共函数索引() {
$getALlCat = $this->Product_model-> getAllCategory();
$data = array();
//Retrieve cart Data
$data['cartItems'] = $this->cart->contents();
//print_r($data);exit;
//$this->load->view('cart/index' ,$data);
///$this->load->helper('url');
/ /$this->load->view('cart/header',['getAllCate'=>$getALlCat], $data); //including header and
footer
$this->load->view('cart/cartbody',['getAllCate'=>$getALlCat], $data);
$this->load->view('common/footer'); //including header and footer
}
}
**This is View page**
<tbody>
<?php if($this->cart->total_items() > 0){ foreach($cartItems as $item){ ?>
<tr>
<td><img src="<?php echo $item['product_image']; ?>" width="50"/></td>
<td><?php echo $item['product_name']; ?></td>
<td><?php echo '$'.$item["product_price"].' USD'; ?></td>
<td><input type="number" class="form-control text-center"></td>
<td><?php echo '$'.$item["subtotal"].' USD'; ?></td>
<td>Are you sue</td>
</tr>
<?php } }else{ ?>
<td colspan="6"><p>Your cart is empty.....</p></td>
<?php } ?>
</tbody>
**Error Showing like this**
A PHP Error was encountered
Severity: Notice
消息:未定义变量:cartItems
文件名:cart/cartbody.php
行号:217
回溯:
文件:C:\xampp\htdocs\shop\application\views\cart\cartbody.php 线路:217 函数:_error_handler
文件:C:\xampp\htdocs\shop\application\controllers\Cart.php 线路:33 功能:查看
文件:C:\xampp\htdocs\shop\index.php 线路:315 函数:require_once
【问题讨论】:
标签: codeigniter