2012-09-29 64 views
1

我想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(); 
    } 
} 

VIEW

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); 
    } 
} 
+0

确保您的型号文件名是小写 – Ula

回答

0

我建议你到自动加载数据库库,因为它会经常用到。您可以在应用程序/配置/ autload.php文件中定义它和变量,

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

你的文件模型的名称应该是,

student_model.php 

和类的名称应该是

Student_model 

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

这是不区分大小写。

`

2

问题是

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

可以看到资本C而不是c

再次发生的事情,请确保您使用<?php开头的文件和?>的结尾文件在?>之后没有任何空格。

0
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. 
0

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

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

/Codeigniter/application.models