调用非对象php ci上的成员函数

时间:2014-01-07 01:51:13

标签: php codeigniter

对不起主人,我的控制器出错了,我是新手PHP CI程序员。 你能帮我解决一下这段代码的错误吗?错误说:“在非对象上调用成员函数produk_list()”

这是我控制器上的代码:

function index()
{
    $data = array();
    $data['template'] = 'produk/index'; 
    $data['query'] = $this->produk_model->produk_list($this->uri->segment(4),5,true);       
    $data['page_title'] = 'Produk';

    $this->pagination->initialize(paging_admin($this->produk_model->count(true),'admin/produk/index'));
    $data['pagination'] =  $this->pagination->create_links();
    $data['breadcrum'] = array(array("MIS Admin Panel",'admin'),
                               array('Produk','admin/produk'),
                               array('List','')
                         );

    $data = array_merge($data,admin_info());
    $this->parser->parse('admin/index',$data);
}

这是我模型上的代码(produk_model)

function produk_list($limit,$offset,$admin = false)
{
    if($admin === false) $this->db->select('id,title,image,content,created_at');
    if($admin === false) $this->db->where('publish',1);
    $this->db->order_by('id','DESC');
    ($limit == '')? $this->db->limit($offset,0) : $this->db->limit($offset,$limit);
    $query = $this->db->get('produk');  
    if($admin === false){
        $data = array();
        foreach($query->result() as $row){
            $data[] = array('produkid' => $row->id,
                            'produktitle' => $row->title,
                            'produkurltitle' => url_title($row->title,'dash',true),
                            'produkdate' => human_date_time($row->created_at),
                            'produkfrontdate' => human_date($row->created_at),
                            'produkimage' => ($row->image != '')? '<img src="{produk_tpath}'.$row->image.'" alt="'.$row->title.'" title="'.$row->title.'" />' : '',
                            'produkcontent' => character_limiter(strip_tags($row->content),200),
                            );
        }
        return $data;
    }else{
        return $query->result();
    }
}

谢谢大师...... 希望你能帮助我...

1 个答案:

答案 0 :(得分:0)

您必须在控制器中加载模型,或者在调用模型函数之前在config下的autoload.php中自动加载模型

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