【问题标题】:CodeIgniter Model Not Found未找到 CodeIgniter 模型
【发布时间】:2012-09-29 08:33:46
【问题描述】:

我正在尝试将 mysql 与 CodeIgniter 连接。我收到了这个错误:

load->database(); 
$query = $this->db->get('student'); return $query->result(); } } ?>

Fatal error: Class 'Student_model' not found in 
C:\wamp\www\CodeIgniter\system\core\Loader.php on line 303

这是我的代码:

型号

class Student_model extends CI_Model
{

    function __Construct()

    {
        parent::__Construct();
    }

    public function student_getall()
    {
        $this->load->database();
        $query = $this->db->get('student');
        return $query->result();
    }
}

查看

foreach($query as $row)
{
    print $row->fname;
    print $row->lname;
    print $row->roll;
    print $row->address;
    print "<br>";
}

控制器

class Student extends CI_Controller
{
    function __Construct()
    {
        parent::__Construct();
    }

    public function getall()
    {
        $this->load->model('student_model');
        $data['query'] = $this->student_model->student_getall();
        $this->load->view('student_view',$data);
    }
}

【问题讨论】:

  • 确保您的模型文件名是小写

标签: php mysql database codeigniter


【解决方案1】:

问题是

function __Construct()
{
        parent::__Construct();
}

您可以看到大写字母C 而不是c

再说一遍,请确保您以 &lt;?php 开头的文件和以 ?&gt; 结尾的文件,?&gt; 之后没有任何空格。

【讨论】:

    【解决方案2】:

    我建议你自动加载数据库库,因为它会经常使用。您可以在 application/config/autload.php 文件中定义它,变量是,

    $autoload['libraries'] = array('database');
    

    你的模型文件名应该是,

    student_model.php
    

    类名应该是

    Student_model
    
    and $this->load->model('student_model') = $this->load->model('Student_model');
    

    这不区分大小写。

    `

    【讨论】:

      【解决方案3】:
      May be your model starts with <?
      And in yuour php.ini, shorttages is off thats why the issue is there.
      Either enable shorttag or user <?php instead of <?
      I found out this solution.
      

      【讨论】:

        【解决方案4】:

        这个

        function __Construct()
        {
            parent::__Construct();
        }
        

        应该是小的'c'。请检查您是否已将student_model.php 正确保存在您的模型文件夹中

        /Codeigniter/application.models

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2015-08-18
          • 1970-01-01
          • 2023-03-18
          • 1970-01-01
          • 1970-01-01
          • 2015-08-29
          相关资源
          最近更新 更多