URL codeigniter 中的问题:我必须手动输入 URL 来检查 errors/results

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

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

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

Message: Undefined variable: query

Message: Trying to get property of non-object

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

我也试过 var_dump 它是的,它不是 NULL。另一个问题是,它告诉我 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; ?> 

查询未定义怎么办?我必须 check/change 我的 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();
    }