CodeIgniter Forums
Problem in generating query - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Problem in generating query (/showthread.php?tid=4763)

Pages: 1 2


Problem in generating query - El Forum - 12-14-2007

[eluser]-spy-[/eluser]
im trying to retrieve my data from the database...but error occured

A PHP Error was encountered
Severity: Notice

Message: Undefined property: Profile::$Student

Filename: controllers/profile.php

Line Number: 11

Fatal error: Call to a member function view_list() on a non-object in D:\Program Files\xampp\htdocs\pupcomm\system\application\controllers\profile.php on line 11...

here's my codes in

controller
Code:
<?php
class Profile extends Controller {

    function Profile()
    {
        parent::Controller();    
    }
    
    function history()
    {
        $data['query'] = $this->Student->view_list();
        $this->load->view('profile/history',$data);
        
    }
}
?>


model
Code:
<?php
class Student extends Model {

    function Student()
    {
        parent::Model();
    }
    
    function view_list()
    {
        $query = $this->db->get('sample_recordlist');
        return $query->result();
    }
}
?>

is there anything wrong?


Problem in generating query - El Forum - 12-14-2007

[eluser]Michael Wales[/eluser]
You have to load the model before you can use it:

Code:
function history()
    {
        $this->load->model('student');
        $data['query'] = $this->Student->view_list();
        $this->load->view('profile/history',$data);
        
    }



Problem in generating query - El Forum - 12-14-2007

[eluser]-spy-[/eluser]
still not working..


Problem in generating query - El Forum - 12-14-2007

[eluser]Michael Wales[/eluser]
Woops - lowercase your call to the model:

Code:
function history() {
  $this->load->model('student');
  $data['query'] = $this->student->view_list();
  $this->load->view('profile/history',$data);
}



Problem in generating query - El Forum - 12-14-2007

[eluser]-spy-[/eluser]
still not working.. maybe it has something to do.. with the error message, but i don't get the point there, hope you can help me..


Problem in generating query - El Forum - 12-14-2007

[eluser]Michael Wales[/eluser]
Maybe I'm just overlooking something simple but I just don't see it.

Do you have a file called: /application/models/student.php?


Problem in generating query - El Forum - 12-14-2007

[eluser]ELRafael[/eluser]
still not working Tongue

Man! What the name of your model file?? Just to check


Problem in generating query - El Forum - 12-14-2007

[eluser]tonanbarbarian[/eluser]
Are you still getting the same error you originally specified?
Is the database actually connected. You need to either have the database in the autoload libraries, or call $this->load->database() from your controller (somewhere before $this->load->model())

and yes as ELRafael is suggesting if your model file is not models/student.php it will not load, although CI should display an error in that case I think.


Problem in generating query - El Forum - 12-14-2007

[eluser]Michael Wales[/eluser]
If CI couldn't connect to a database defined in the database.php that would be the first error he would receive.

He's not even getting to the point of trying to call the database yet though - CI can't find the object Student (therefore, it's not even worried about the database calls within it's member function yet).

It has to be the filename...


Problem in generating query - El Forum - 12-14-2007

[eluser]tonanbarbarian[/eluser]
how about you post again the controller and model file including details about the filesnames i.e. application/controllers/xxx.php and application/models/yyy.php