如何在CodeIgniter中调试未定义的变量问题?

时间:2017-01-01 18:10:24

标签: php sql codeigniter

控制器

<?php
class delete_ctrl extends CI_Controller{
function __construct(){
parent::__construct();
$this->load->model('delete_model');
}
// Function to Fetch selected record from database.
function show_product_id() {
$id = $this->uri->segment(3);
$data['products'] = $this->delete_model->show_products();
$data['single_product'] = $this->delete_model->show_product_id($id);
$this->load->view('deletepro_view', $data);
}
// Function to Delete selected record from database.
function delete_product_id() {
$id = $this->uri->segment(3);
$this->delete_model->delete_product_id($id);
$this->show_product_id();
}
}

模型

<?php
class delete_model extends CI_Model{
// Function to select all from table name students.
function show_products(){
$query = $this->db->get('product');
$query_result = $query->result();
return $query_result;
}
// Function to select particular record from table name students.
function show_product_id($data){
$this->db->select('*');
$this->db->from('product');
$this->db->where('id', $data);
$query = $this->db->get();
$result = $query->result();
return $result;
}
// Function to Delete selected record from table name students.
function delete_product_id($id){
$this->db->where('id', $id);
$this->db->delete('product');
}
}
?> 

查看

<?php
?>
<!DOCTYPE html>
<html>
<head>

<link href='http://fonts.googleapis.com/css?family=Marcellus' rel='stylesheet' type='text/css'> <!--google fonts-->
<link href="<?php echo base_url()?>./css/delete.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="container">
<div id="wrapper">
<h1>Delete Product From Database</h1>
<div id="menu">
<p>Click the product to be deleted</p>
<!--====== Displaying Fetched Names from Database in Links ========-->
<ol>
<?php
foreach ($products as $product): ?>
<li><a href="<?php echo base_url() . "index.php/delete_controller/show_product_id/" . $product->id; ?>"><?php echo $product->name; ?></a>
</li><?php endforeach; ?>
</ol>
</div>
<div id="detail">
<!--====== Displaying Fetched Details from Database ========-->

<?php foreach ($single_product as $product): ?>

<!--====== Delete Button ========-->
<a href="<?php echo base_url() . "index.php/delete_contrller/delete_product_id/" . $product->id; ?>">
<button>Delete</button></a>
<?php endforeach; ?>
</div>
</div>
</div>
</body>
</html>

我有这个错误

  

遇到PHP错误   严重性:通知
  消息:未定义的变量:产品
  文件名:views / deletepro_view.php
  行号:19
  回溯:
  文件:C:\ wamp \ www \ BakeBookProject \ application \ views \ deletepro_view.php
  行:19
  功能:_error_handler
  文件:C:\ wamp \ www \ BakeBookProject \ application \ controllers \ Welcome.php   行:23
  功能:查看
  文件:C:\ wamp \ www \ BakeBookProject \ index.php
  线:315
  功能:require_once

0 个答案:

没有答案