在非对象上调用成员函数result()

时间:2016-02-29 00:44:25

标签: php database codeigniter

加载视图时出现错误消息。 “在非对象”

上调用成员函数result()

我该如何解决这个问题?

这是我的视图中的循环:discussion / view.php

<?php foreach ($query->result() as $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 ; ?>

这是我的评论控制器中的函数索引:

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

0 个答案:

没有答案