doupao6011 2014-08-23 08:15
浏览 51

Codeigniter-致命错误:在非对象上调用成员函数get_news()

When I try to run a simple function it shows me:

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Site::$model_users

Filename: controllers/site.php

Line Number: 14

Fatal error: Call to a member function get_news() on a non-object in /hermes/bosoraweb130/b418/ipg.blazewarcom/ci/application/controllers/site.php on line 14

The functions:

model_users.php located in models folder:

public function get_news()
{
    $query = $this->db->query("SELECT * FROM tblnews ORDER BY newId DESC LIMIT 3");
    return $query;
}

site.php located in controllers folder:

public function home_news() {
        $query = $this->model_users->get_news(); //This line causes the problem
        ...
        ...
}
  • 写回答

2条回答 默认 最新

  • douyuan9512 2014-08-23 08:19
    关注

    Don't you just want to call the method get_news() on $this class?

    Try

    class Site {
       public function home_news() {
            $class_name = new Class_Name();  //change Class_Name() to the class that has the method get_news.
            $query = $class_name->get_news(); //This line caused the problem
            ...
            ...
       }
    }
    

    Hope this helps.

    评论

报告相同问题?

悬赏问题

  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。
  • ¥20 CST怎么把天线放在座椅环境中并仿真
  • ¥15 任务A:大数据平台搭建(容器环境)怎么做呢?