php codeigniter:调用未定义的方法CI_Loader :: model() [英] php codeigniter: Call to undefined method CI_Loader::model()

查看:191
本文介绍了php codeigniter:调用未定义的方法CI_Loader :: model()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用codeigniter制作一个Web应用程序,但这已经有一段时间了,因为我已经使用了它,并且每当我尝试在控制器中加载模型时都会出现错误.我可能正在做一些愚蠢的错误,但我不知道这是什么.所以,如果可以的话,请帮助我.

I wanted to make a webapplication using codeigniter but it is a while since I've used it and I'm getting an error whenever I try to load a model in my controller. I'm probably doing something stupid wrong but I can't figure out what it is. So please help me out if u can.

这是我得到的错误:

这是我的模型的代码:

<?php 

class post_model extends CI_Model {

    function __construct() {
        parent::__construct();
    }

    function getAllPosts() {
        $this->db->order_by('date', 'desc');
        $query = $this->db->get('post');
        return $query->result();
    }
}
?>

这是我加载模型的控制器代码:

Here is the code of my controller where I load the model:

<?php 

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

class Post extends CI_Controller {

    public function __construct() {
        parent::__construct();

        $this->load->model('post_model');
    }

    public function index() {
        $data['title'] = 'Berichten';
        $data['posts'] = $this->post_model->getAllPosts();

        $this->template->load('posts', $data);
    }
}

自动加载:

$autoload['helper'] = array('url', 'form', 'date');
$autoload['model'] = array();

已解决:我无法解决它,但是我创建了一个新项目并复制粘贴了我的代码,现在它可以正常工作,所以不知道出了什么问题.

Solved: I couldn't solve it but I made a new project and copy-pasted my code and now it works just fine, so no idea what was wrong.

推荐答案

所有类的首字母应大写

class Post_model extends CI_Model {

在第11行加载模型时会引发错误

This throws the error when loading the model at line 11

这篇关于php codeigniter:调用未定义的方法CI_Loader :: model()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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