Reputation: 41
I am trying to connect mysql with CodeIgniter. I got this error:
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
Here is my code:
MODEL
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>";
}
CONTROLLER
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);
}
}
Upvotes: 1
Views: 9329
Reputation: 23
This
function __Construct()
{
parent::__Construct();
}
should be small 'c' s. Please check if you have correctly saved student_model.php
in your models folder in
/Codeigniter/application.models
Upvotes: 0
Reputation: 184
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.
Upvotes: 0
Reputation: 646
the problem is
function __Construct()
{
parent::__Construct();
}
you can see the capital C
instead of c
.
Once more thing, make sure that you started with file using <?php
and ending file with ?>
without any space after ?>
.
Upvotes: 2
Reputation: 2551
I suggest you to load the database library automatically, since it will be used frequently. You can define it in application/config/autload.php file and the variable is,
$autoload['libraries'] = array('database');
You file name of the model should be,
student_model.php
and the class name should be
Student_model
and $this->load->model('student_model') = $this->load->model('Student_model');
this is not case sensitive.
`
Upvotes: 0