严重性:注意 尝试获取非对象的属性,但未从数据库表代码点火器获取任何数据



我正在用代码点火器做一个项目。在这里,我收到一个错误"尝试获取非对象代码点火器的属性"。我已经尝试了下面给出的一些代码,我是一个尝试学习代码的新手,因此请在这方面帮助我。 控制器代码:-

class Cart extends CI_Controller{
//put your code here
public function __construct() {
parent::__construct();
$this->load->model('Cart_model');
$this->load->library('cart');
}
public function add_to_cart(){
$product_id= $this->input->post('product_id',true);
$category_info= $this->Cart_model->select_product_info_by_product_id($product_id);
$data = array(
'id'      =>$category_info->product_id,
'price'   => $category_info->product_price,
'name'    => $category_info->product_name,
'options' => array('image' => $category_info->product_image)
);
echo '<pre>';
print_r($data);
exit();
$this->cart->insert($data);
$this->load->view('Cart/show_cart');
}
}

型号:-

class Cart_model extends CI_Model{
//put your code here
public function select_product_info_by_product_id($product_id) {
$product_info= $this->db->select('*')
->from('tbl_product')
->where('product_id',$product_id)
->get()->row();
return $product_info;
} 
}

每当我运行代码时,我都会收到这样的错误:-

严重性:通知 消息:尝试获取非对象的属性"product_id">

严重性:通知 消息:尝试获取非对象的属性"product_price">

严重性:通知 消息:尝试获取非对象的属性"product_name">

严重性:通知 消息:尝试获取非对象的属性"product_image">

而且我在数组中也没有获得任何值。

Array
(
[id] => 
[price] => 
[name] => 
[options] => Array
(
[image] => 
)
)

我没有product_id,我忘了在我的视图页面中命名"product_id"。当我在查看页面中放置name='product_id'时,这实际上解决了问题。

最新更新