duanjiashai9140 2016-05-30 13:56 采纳率: 0%
浏览 55
已采纳

CodeIgniter 3未定义属性:MY_Output :: $ load

I wonder if I can get some insight into this problem. I am developing a CI3 website which works fine on GoDaddy (Linux shared hosting), but for some reason the same exact code and same database is producing errors on my local server (my Windows 10 laptop).

I have changed all the config/config.php constants, as well as the config/database.php constants to reflect the local settings.

My config.php base_url:

$config['base_url'] = 'http://simplereo/';

I set up the virtual server simplereo in my host file in Windows, and set up a virtual server in my httpd.conf in Apache, which I have plenty of experience doing, so the local virtual web server is working.

The specific error I get is:

A PHP Error was encountered

Severity: Notice

Message: Undefined property: MY_Output::$load

Filename: core/My_Output.php

Line Number: 8

Backtrace:

File: C:\xampp\htdocs\simplereo\application\core\My_Output.php
Line: 8
Function: _error_handler

File: C:\xampp\htdocs\simplereo\index.php
Line: 302
Function: require_once

The error refers to my MY_OUTPUT class file. The application\core\MY_OUTPUT.php file contains this code:

class MY_Output extends CI_Output {

function __construct()
{
    parent::__construct();
    $this->load->model('user_model');
    $this->load->helper('cookie');
    $this->config->load('security');
    $this->load->library('session');
    $this->load->helper('url');
}

function nocache()
{
    $this->set_header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
    $this->set_header('Cache-Control: no-cache, no-store, must-revalidate, max-age=0');
    $this->set_header('Cache-Control: post-check=0, pre-check=0', FALSE);
    $this->set_header('Pragma: no-cache');
}

}

Although $this->load->model('user_model'); occurs on line 8, I'm pretty sure that line isn't specifically the problem, because I can shuffle the order of the loads, and it will still error out on line 8, or I can eliminate line 8 altogether, and the error will just move on to the next line. Not sure why everything works on the remote server, but not on my local server.

* I think this is the answer: * I took out the first function:

function __construct()
{
    parent::__construct();
    $this->load->model('user_model');
    $this->load->helper('cookie');
    $this->config->load('security');
    $this->load->library('session');
    $this->load->helper('url');
}

...and I'm not getting any errors. Do I even need that __construct()? I may have put it in originally for no good reason.

  • 写回答

1条回答 默认 最新

  • dongwo5940 2016-05-30 14:53
    关注

    I am not sure, but in general if you override or create your own libraries, $this->load doesn't work because $this only works directly within your controllers, your models, or your views. If you would like to use CodeIgniter's classes from within your own custom classes you can do so as follows:

    $CI =& get_instance();
    
    $CI->load->model('user_model');
    

    PS: Read more about it on CI documentation

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛