嗨,我是Codeigniter的新手。遇到PHP错误

时间:2017-02-09 04:14:20

标签: codeigniter

A PHP Error was encountered

Severity: Notice

Message: Undefined property: News::$News_model

Filename: controllers/News.php

Line Number: 14

Backtrace:

File: /Applications/MAMP/htdocs/workshop10/application/controllers/News.php
Line: 14
Function: _error_handler

File: /Applications/MAMP/htdocs/workshop10/index.php
Line: 315
Function: require_once

我的控制员:

defined('BASEPATH') OR exit('No direct script access allowed');

class News extends CI_Controller {

     public function index()
     {
          $data['theNews'] = array("All your base are belong to us!",
                                 "Autotune this news",
                                  "Numa Numa!!",
                                  $this->News_model->get_new_news()
                                );
          $this->load->view('templates/news_header');
          $this->load->view('new_items',$data);
          $this->load->view('templates/news_footer');
    }
}

我的模特:

class News_model extends CI_Model {

    var $title = '';
    var $content = '';
    var $date = '';
    public function __construct()
    {
    //call the Model constuctor
    parent::__construct();
    }
    public function get_new_news()
    {
    return "Something Kool";
    }
}

我的观点:

 <?php
 foreach ($theNews as $news_item) { ?>
 <div><?php echo $news_item; ?></div>
<?php } ?>

2 个答案:

答案 0 :(得分:0)

你没有在控制器上加载模型文件

使用此$this->load->model('News_model');

答案 1 :(得分:0)

在您的控制器中。使用以下代码。

1.7.x