在第11行调用C:\ xampp\htdocs\CodeIgniter_Practice\application\controllers\\\<br/>ews.php中的非对象的成员函数get_news() [英] Call to a member function get_news() on a non-object in C:\xampp\htdocs\CodeIgniter_Practice\application\controllers\news.php on line 11

查看:130
本文介绍了在第11行调用C:\ xampp\htdocs\CodeIgniter_Practice\application\controllers\\\<br/>ews.php中的非对象的成员函数get_news()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从CodeIgnitor用户指南写了一个小应用程序,但当我运行它,显示给定的消息

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\news.php on line 11

代码是

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');
  }
}

第11行是:

$data['news'] = $this->news_model->get_news();


推荐答案

通过查看代码, 've missed one' _ '(下划线)。
它必须如下:

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');
 }  

这篇关于在第11行调用C:\ xampp\htdocs\CodeIgniter_Practice\application\controllers\\\<br/>ews.php中的非对象的成员函数get_news()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆