codeigniter新闻栏目教程无法正常工作 [英] codeigniter news section tutorial not working

查看:71
本文介绍了codeigniter新闻栏目教程无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我要通过有关Codeigniter的新闻部分教程,但出现以下错误

hey guys im going thru the news section tutorial on codeigniter and i get the following error

A PHP Error was encountered

Severity: Notice

Message: Undefined property: News::$db

Filename: core/Model.php

Line Number: 77

Backtrace:

File: /Applications/MAMP/htdocs/CodeIgniter/application/models/News_model.php
Line: 13
Function: __get

File: /Applications/MAMP/htdocs/CodeIgniter/application/controllers/News.php
Line: 10
Function: get_news

File: /Applications/MAMP/htdocs/CodeIgniter/index.php
Line: 292
Function: require_once

我所做的只是简单地复制了教程中提供的内容,这是我的文件

All i did was simply copy what was provided in the tutorial, here are my files

news_model.php文件

news_model.php file

<?php

class News_model extends CI_Model {

    public function __constrcut() {
        $this->load->database();
    }

    public function get_news($slug = FALSE) {

        if ($slug === FALSE ) {

            $query = $this->db->get('news');
            return $query->result_array();
        }


        $query = $this->db->get_where('news', array('slug' => $slug));
        return $query->row_array();
    }
}

news.php

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

    public function view($slug) {
        $data['news'] = $this->news_model->get_news($slug);

        if (empty($data['news_item'])) {
            show_404();

        }

        $data['title'] = $data['news_item']['title'];
        $this->load->view('templates/header',$data);
        $this->load->view('news/view',$data);
        $this->load->view('templates/footer');

    }

}

这是我的文件结构的图片

and here is a picture of my file structure

我正尽力学习和调试,但我不知道这可能是什么.

im trying my best to learn and debug but i dont know what it could be.

推荐答案

也许未加载数据库库.您必须加载数据库库.

Maybe, database library is not loaded. you have to load database library.

应用程序/配置/autoload.php

application / config / autoload.php

 $autoload['libraries'] = array('database');

这篇关于codeigniter新闻栏目教程无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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