代码点火器中的 URL 问题:我必须手动键入 URL 来检查错误/结果


URL problems in codeigniter: I have to manually type URL to check errors/results

我没有得到Codeigniter URL。 我目前的base_url是http://localhost/codeigniter/

我想从数据库中检索数据,但它总是告诉我

消息:未定义的变量:查询

消息:尝试获取非对象的属性

我确定我的控制器、模型和视图工作正常。我的数据库不是空的,但每次我输入这个 url http://localhost/codeigniter/index.php/c_test/它不会显示结果/错误,我必须始终指定 URL 以查看我是否http://localhost/codeigniter/index.php/c_test/getgrades收到错误(请注意,我必须添加 getGrades,以便我可以看到结果)

我也试图var_dump它,是的,它不是空的。另一个问题是,它告诉我Message: Undefined variable: query原因是什么?

(我会给你看代码,这样你就会明白我的意思)控制器:

function getGrades() {
       $data['query'] = $this->m_test->result_getGrades(); 
       $this->load->view('v_display', $data);
    }

型:

function result_getGrades()
    {
          $this->db->select('grades.blockcode,subjectblocking.subjectcode,subjects.description,grades.final');
          $this->db->from('grades');
          $this->db->join('subjectblocking','grades.blockcode=subjectblocking.blockcode');
          $this->db->join('subjects','subjectblocking.subjectcode=subject.subjectcode');
          $query->$this->db->get();
          return $query->result();
    }

视图:

 <?php foreach ($query as $row): ?>
               <?php echo $row->studentid;?><br>
               <?php echo $row->subjectcode;?><br>
               <?php echo $row->description;?><br>
               <?php echo $row->final;?><br>

         <?php endforeach; ?> 

为什么查询未定义?我必须检查/更改config.phpautoload.php上的某些内容吗?

尝试替换一行 $query->$this->db->get(); 到 $query = $this->db->get(); 在你的模型函数中,

function result_getGrades()
    {
          $this->db->select('grades.blockcode,subjectblocking.subjectcode,subjects.description,grades.final');
          $this->db->from('grades');
          $this->db->join('subjectblocking','grades.blockcode=subjectblocking.blockcode');
          $this->db->join('subjects','subjectblocking.subjectcode=subject.subjectcode');
          $query = $this->db->get();
          return $query->result();
    }