遇到PHP错误严重性:通知消息:未定义属性:Social :: $ social_model文件名:controllers / social.php行号:10

时间:2014-02-19 20:33:11

标签: php codeigniter-2

在运行codeigniter时出现以下错误:

  

遇到PHP错误严重性:通知消息:未定义属性:Social :: $ social_model文件名:controllers / social.php行号:10

我的代码有什么问题吗?

controllers/social.php

class Social extends CI_Controller {

    public function index(){

            $data = array();
            $this->load->view('header.php');
            $this->load->view('staffs/content.php');
            if ($query = $this-> social_model -> get_records()) // **[line 10]**
            {
                $data['records'] = $query;
            }

            $this->load->view('social/content.php', $data); 
            $this->load->view('footer.php');
        }

   // ....
}

models/social_model.php

<?php
class  social_model extends CI_Model{

    function get_records()
    {
        $query = $this->db->get('admins');
        return $query -> result();
    }

   // ....
}

1 个答案:

答案 0 :(得分:1)

您必须加载模型:

$this->load->model('social_model');