gpt4 book ai didi

php - CI 模型加载不正确?

转载 作者:行者123 更新时间:2023-11-29 00:13:57 25 4
gpt4 key购买 nike

public function __construct()
{
parent::__construct();
$this->load->database();
$this->load->helper('login');
$this->load->model('profile_model');
$this->load->model('common_model');
}
function index()
{
$this->user_information();
}
function user_information()
{
if($this->input->post('submit'))
{

}
else
{
$data['settings']=$this->common_model->get_user_settings();
$this->load->view('profile/user-settings',$data);
}
}

遇到 PHP 错误

Severity: Notice

Message: Undefined property: Settings::$common_model

Filename: controllers/settings.php

Line Number: 24

Fatal error: Call to a member function get_user_settings() on a non-object in D:\xampp\htdocs\dandalo\application\controllers\settings.php on line 24

这是我的代码。我收到此错误。我不知道我正确加载模型时怎么会出现这种错误。

模型代码:

<?php
class common_model extends CI_Model
{
public $datet;
public function __construct()
{
parent::__construct();
$this->load->database();
//$this->load->model('buy_model');
$this->datet=date('Y-m-d H:i:s');
}
function get_user_settings()
{
$this->db->select('user_name,u_first_name,u_last_name,u_email,u_profile_image,fb_id');
$this->db->where('user_id',user_id());
return $this->db->get('en_user')->result();
}}?>

这是我的模型代码。我还扩展了 CI_model。我仍然收到错误。

最佳答案

application/models 中找到您的模型

profile_model.php
common_model.php

你的模型类看起来像

class ProfileModel extends CI_Model
class CommonModel extends CI_Model

加载 Controller

$this->load->model('profile');
$this->load->model('common');

然后调用模型函数

$data['settings']=$this->common->get_user_settings();

更多信息:- http://ellislab.com/codeigniter/user-guide/general/models.html

关于php - CI 模型加载不正确?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23629819/

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