代码点火器3错误未定义的属性



错误代码

遇到PHP错误

严重性:注意

消息:未定义的属性:CI_Loader::$yamaha_model

文件名:controllers/Yamaha.php

线路编号:12

回溯:

文件:/home/billionp/domains/billionproonline.com/public_html/bpp_8/application/controllers/Yamaha.php行:12函数:_error_handler

文件:/home/billionp/domains/billionproonline.com/public_html/bp_8/index.php线路:295功能:require_one

致命错误:在中的非对象上调用成员函数product()/home/billionp/domains/billionproonline.com/public_html/bpp_8/application/controllers/Yamaha.php在线12

遇到PHP错误

严重性:错误

消息:在非对象上调用成员函数product()

文件名:controllers/Yamaha.php

线路编号:12

回溯:

控制器

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Yamaha extends CI_Controller {
public function index(){        
$template = array(
'title' => 'YAMAHA',
'heading' => 'My Heading',
'message' => 'My Message'
);
$contents['row'] = $this->load->yamaha_model->product();    
// $contents['row']          = $this->yamaha_model->product();
$contents['cart_session'] = $this->session->userdata('cart_session');
$template['content']      = $this->load->view('yamaha',$contents,TRUE);
$this->load->view('template',$template);
}
}

型号:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Yamaha_model extends CI_Model {
function __construct() {
parent::__construct();
}   
function product(){
return $i = $this->db->select('*')->from('yamaha')->get()->result();
}
function product_detail($id){
return $i = $this->db->select('*')->from('yamaha')->where('product_id',$id)->get()->row();
}
}

这是一个有趣的用法,但似乎不能先链式加载模型,然后再调用方法。它需要显式加载。

所以改变

$contents['row'] = $this->load->yamaha_model->product();

到此

$this->load->model('yamaha_model');
$contents['row'] = $this->yamaha_model->product(); 

最新更新