我的程序中出現錯誤。在這個程序中,我希望如果periode活動顯示數據,當periode活動但是當periode不活動時不顯示數據任何東西。但我嘗試這個條件,我得到錯誤嘗試獲取模型中的非對象的屬性。試圖在模型codeigniter中獲取非對象的屬性
這是模態
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'] = '«';
$config['prev_page'] = '»';
$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);
請告訴我如何解決這個錯誤。
謝謝。
發佈你的錯誤,請.. –
我們可以聊聊嗎?我需要你的幫助 – user3622745