【问题标题】:Need help on Codeigniter to solve an error on Controller and Model在 Codeigniter 上需要帮助以解决控制器和模型上的错误
【发布时间】:2014-03-29 15:21:26
【问题描述】:

模型/blogmodel.php:

class Blogmodel extends CI_Model {
    public function get_recent_post($num){
        $query = $this->db->get('wdr_blog_post', $num);
        return $query->result();
    }
}

控制器/blog.php:

class Blog extends CI_Controller {
    public function index(){
        $this->load->model('blogmodel');
        $posts = $this->Blogmodel->get_recent_post(5);
    }
}

错误:

遇到 PHP 错误

严重性:通知

消息:未定义属性:Blog::$Blogmodel

文件名:controllers/blog.php

行号:7

致命错误:在第 7 行对 G:\server\htdocs\xyz\app\controllers\blog.php 中的非对象调用成员函数 get_recent_post()

【问题讨论】:

  • $this->blogmodel 应该是小写的!

标签: php codeigniter model controller


【解决方案1】:

只是猜测......

class Blog extends CI_Controller {
    public function index(){
        $this->Blogmodel = $this->load->model('blogmodel');
        $posts = $this->Blogmodel->get_recent_post(5);
    }
}

【讨论】:

  • 非常感谢。第一个错误解决了。但仍然显示“Fatal error: Call to a member function get_recent_post() on a non-object in G:\server\htdocs\xyz\app\controllers\blog.php on line 7”跨度>
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-09
  • 1970-01-01
  • 2019-07-17
  • 2021-09-10
  • 2021-12-11
相关资源
最近更新 更多