php - 尝试获取模型 codeigniter 中非对象的属性

标签 php mysql sql codeigniter

我的程序出现错误。在这个程序中,我想让如果periode处于事件状态则在periode处于事件状态时显示数据,但是当periode不处于事件状态时不显示任何数据。但我尝试这种情况时出现错误尝试获取模型中非对象的属性。

这是模态

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;
    }

这是我的 Controller

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;

关于php - 尝试获取模型 codeigniter 中非对象的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23797304/

相关文章:

php - Mysql 不保留来自 Jquery ajax post 的换行符?

MySQL 在连接表时选择 SUM

c# - 将数据库中的图像注入(inject)到 sql 报告查询中

sql - 跨连接表获取多个计数

MySQL 查找匹配的行集

php - 如何对齐不同大小的图像

php - 获取所选列的总和

php - 如何为元素数组动态创建查询?

mysql - 在 MySQL 中,使用 @vars 时 VIEW 与 TABLE 的结果不同

mysql - 连接到数据库时未处理 SocketException