【问题标题】:codeigniter 3 ERROR Undefined propertycodeigniter 3 错误未定义的属性
【发布时间】:2018-01-24 22:21:33
【问题描述】:

错误代码

遇到了 PHP 错误

严重性:通知

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

文件名:控制器/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/bpp_8/index.php 行:295 功能:require_once

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

遇到了 PHP 错误

严重性:错误

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

文件名:控制器/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();
    }
}

【问题讨论】:

  • 你试过在构造函数中加载模型吗?

标签: php jquery html css codeigniter


【解决方案1】:

有趣的用法,但您似乎无法链接加载模型然后调用方法。它需要显式加载。

所以改变

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

到这里

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

【讨论】:

  • 谢谢你,我们会尽你所能。
猜你喜欢
  • 1970-01-01
  • 2014-11-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-27
  • 1970-01-01
相关资源
最近更新 更多