试图在模型编码器中获得非对象的属性


Trying to get property of non-object in model codeigniter

我的程序出错了。在这个程序中,我想让if周期处于活动状态时显示数据当周期处于活动状态时不显示任何数据。但我尝试这个条件,我得到错误试图得到模型中的非对象的属性。

this is modal

function get_id_periode_open()
    {
        $this->db->where('tgl_dari <= curdate()');
        $this->db->where('tgl_sampai >= curdate()');
        // $this->db->where('status', 'open');
        $row = $this->db->get('periode')->row();
        $id_periode = $row->id_periode; //line error
        return $id_periode;
    }

这是我的控制器

function index($nama = '',$period = 0,$geup = 0)
    {
        $this->load->model('mukt');
        $id_periode = $this->mukt->get_id_periode_open();
        $this->data['id_periode_sekarang'] = $id_periode;
        if ($id_periode) 
        {
            $this->data['ukt2'] = $this->mukt->get_ukt($perpage,$offset);
        }
        else
        {
            echo "string";
            $this->data['contents'] = '<div class="twelve wide column">Tidak ada periode aktif</div>';
        }

        if (!$nama AND $this->input->post('nama')) 
        {
            $nama = $this->input->post('nama');
        }   
        else if(!$nama)
        {
            $nama = 0;
        }
        if ($this->input->post('id_periode')){
            $period = $this->input->post('id_periode');
        }
        else if(!$period)
        {
            $period = 0;
        }
        if ($this->input->post('geup')){
            $geup = $this->input->post('geup');
        }
        else if(!$geup)
        {
            $geup = 0;
        }else{
            $geup = urldecode($geup);
        }
        // echo $period. urldecode($geup). $nama;
        $count = $this->mukt->get_count_peserta_ukt($period, urldecode($geup), $nama);
        // print_r($count);
     //    exit;
        // Set up pagination
        $offset = 0;
        $perpage = 1;
        $uri_segment = 6;
        if ($count > $perpage) {
            $this->load->library('pagination');
            $this->load->config('pagination');
            $config = $this->config->item('pag');   
            $config['base_url'] = site_url('pelatih/ukt/'.$nama.'/'.$period.'/'.$geup);
            $config['total_rows'] = $count;
            $config['per_page'] = $perpage;
            $config['uri_segment'] = $uri_segment;
            $config['first_page'] = 'Awal';
            $config['last_page'] = 'Akhir';
            $config['next_page'] = '&laquo;';
            $config['prev_page'] = '&raquo;';
            $this->pagination->initialize($config);
            $this->data['pagination'] = $this->pagination->create_links();
            if($this->uri->segment($uri_segment)){
                $offset = $this->uri->segment($uri_segment);
            }
        }
        else {
            $this->data['pagination'] = '';
            $offset = 0;
        }
        $this->data['periode'] = $this->mperiode->get_periode();

        if ($period AND $geup)
        {   
            $this->data['ukt2'] = $this->mukt->get_cari_peserta_ukt($period, $geup ,$nama,$perpage,$offset);
        }
        else if($nama && (!$period || !$this->input->post('geup')))
        {
            $this->data['ukt2'] = $this->mukt->get_cari_peserta_ukt("", "",$nama,$perpage,$offset);
        }
        else
        {
            $this->data['ukt2'] = $this->mukt->get_ukt($perpage,$offset);
        }

        $this->data['title'] ='UKM Taekwondo | ukt';
        $this->data['orang'] = $this->mlogin->dataPengguna($this->session->userdata('username'));
        $this->data['contents'] = $this->load->view('pelatih/ukt/view_ukt', $this->data, true);
        $this->load->view('template/wrapper/pelatih/wrapper_anggota',$this->data);

请告诉我如何解决这个错误。

谢谢。

可能是您的查询没有返回结果,所以尝试:

$query = $this->db->get('periode');
if( $query->num_rows() > 0 ) {
    $row = $query->row();
    $id_periode = $row->id_periode;
    return $id_periode;
}
return 0;