所以我试图制作一个产品的详细信息页面,从产品列表链接。我已经配置了路由。但是该页面显示未定义的 foreach 变量出错。
这是错误:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: listproduk
Filename: user/view.php
Line Number: 28
Backtrace:
File: E:\xampp\htdocs\emedco\application\views\user\view.php
Line: 28
Function: _error_handler
File: E:\xampp\htdocs\emedco\application\controllers\ProdukList.php
Line: 19
Function: view
File: E:\xampp\htdocs\emedco\index.php
Line: 315
Function: require_once
详情页,view.php
<div class="container-fluid">
<h4>Detail</h4>
<h2><?php echo $listproduk['nama_produk']; ?></h2> <!--line 28-->
<p><?php echo $listproduk['deskripsi_produk']; ?></p>
</div>
产品列表视图(详细视图之前的前一页,没有错误),produklist.php
<?php foreach ($produk as $listproduk) : ?>
<div class="col-6 col-md-4 col-xl-3 mb-4 ">
<div class="card text-center shadow h-100 py-2">
<img class="card-img-top" src="<?php echo base_url('images/product/' . $listproduk['img_produk']) ?>" width="100" alt="Card image cap">
<div class="card-body">
<h6 class="card-title"><?php echo $listproduk['nama_produk']; ?></h6>
<p style="font-size:80%;" class="card-text">Kategori obat</p>
<p style="font-size:80%;" class="card-text">Rp. <?php echo $listproduk['harga_produk']; ?></p>
</div>
<div class="card-footer">
<a href="<?php echo site_url('ProdukList/'.$listproduk['kode_produk']); ?>" class="btn btn-primary btn-block btn-sm">Detail</a>
</div>
</div>
</div>
<?php endforeach; ?>
控制器,ProdukList.php
<?php
class ProdukList extends CI_Controller
{
public function index()
{
$data['produk'] = $this->ProdukList_model->get_produk();
$this->load->view('user/produklist', $data);
}
试图在 $data 之后添加 true,并且$this->load->view('user/view', $data, true);它显示空白页面。
尚方宝剑之说
狐的传说
郎朗坤