php - Call to a member function result() on a non-object -
there error message when view being loaded. "call member function result() on non-object"
how fix this?
this loop in view: discussion/view.php
<?php foreach ($query->result() $result) : ?> <tr> <td> <?php echo anchor('comments/index/'.$result->ds_id,$result->ds_title) . ' ' . $this->lang->line('comments_created_by') . $result->usr_name; ?> <?php echo anchor('discussions/flag/'.$result->ds_id, $this->lang->line('discussion_flag')) ; ?> <br /> <?php echo $result->ds_body ; ?> </td> </tr> <?php endforeach ; ?>
and function index in comments controller:
public function index() { if ($this->input->post()) { $ds_id = $this->input->post('ds_id'); } else { $ds_id = $this->uri->segment(3); } $page_data['discussion_query'] = $this->discussions_model->fetch_discussion($ds_id); $page_data['comment_query'] = $this->comments_model->fetch_comments($ds_id); $page_data['ds_id'] = $ds_id; $this->form_validation->set_rules('ds_id', $this->lang->line('comments_comment_hidden_id'), 'required|min_length[1]|max_length[11]'); $this->form_validation->set_rules('comment_name', $this->lang->line('comments_comment_name'), 'required|min_length[1]|max_length[25]'); $this->form_validation->set_rules('comment_email', $this->lang->line('comments_comment_email'), 'required|min_length[1]|max_length[255]'); $this->form_validation->set_rules('comment_body', $this->lang->line('comments_comment_body'), 'required|min_length[1]|max_length[5000]'); if ($this->form_validation->run() == false) { $this->load->view('common/header'); $this->load->view('nav/top_nav'); $this->load->view('comments/view', $page_data); $this->load->view('common/footer'); } else { $data = array('cm_body' => $this->input->post('comment_body'), 'usr_email' => $this->input->post('comment_email'), 'usr_name' => $this->input->post('comment_name'), 'ds_id' => $this->input->post('ds_id') ); if ($this->comments_model->new_comment($data)) { redirect('comments/index/'.$ds_id); } else { // error $this->data['message'] = 'error!'; } } }
Comments
Post a Comment