doutong4088 2013-11-26 04:46
浏览 64
已采纳

在第11行的C:\ xampp \ htdocs \ CodeIgniter_Practice \ application \ controllers ews.php中的非对象上调用成员函数get_news()

I wrote a small application from CodeIgnitor user guide but when I run it, display the given message

Fatal error: Call to a member function get_news() on a non-object in C:\xampp\htdocs\CodeIgniter_Practice\application\controllers
ews.php on line 11

The code is

class News extends CI_Controller{
  public function _construct()    
  {
     parent::_construct();   
     $this->load->model('news_model');
  }
  public function index()
  {
  $data['news'] = $this->news_model->get_news(); 
     $data['title'] = 'News archive';

     $this->load->view('templates/header',$data);
     $this->load->view('news/index',$data);
     $this->load->view('templates/footer');
  }
}

Line 11 is :

$data['news'] = $this->news_model->get_news();
  • 写回答

2条回答 默认 最新

  • douyan6871 2013-11-26 05:04
    关注

    By looking at your code, i could see that you've missed one '_'(underscore) while defining your construct. It has to be as below:

    public function __construct()    
    {
      parent::__construct();   
      $this->load->model('news_model');
     }  
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划