gpt4 book ai didi

php - codeigniter 3 错误未定义的属性

转载 作者:行者123 更新时间:2023-11-28 17:07:40 25 4
gpt4 key购买 nike

错误代码

遇到 PHP 错误

Severity: Notice

Message: Undefined property: CI_Loader::$yamaha_model

Filename: controllers/Yamaha.php

Line Number: 12

Backtrace:

File: /home/billionp/domains/billionproonline.com/public_html/bpp_8/application/controllers/Yamaha.php Line: 12 Function: _error_handler

File: /home/billionp/domains/billionproonline.com/public_html/bpp_8/index.php Line: 295 Function: require_once

Fatal error: Call to a member function product() on a non-object in /home/billionp/domains/billionproonline.com/public_html/bpp_8/application/controllers/Yamaha.php on line 12

遇到 PHP 错误

Severity: Error

Message: Call to a member function product() on a non-object

Filename: controllers/Yamaha.php

Line Number: 12

Backtrace:

Controller

<?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();

关于php - codeigniter 3 错误未定义的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48424239/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com