Welcome Guest, Not a member yet? Register   Sign In
Problem in generating query
#1

[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?
#2

[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);
        
    }
#3

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

[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);
}
#5

[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..
#6

[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?
#7

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

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

[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.
#9

[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...
#10

[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




Theme © iAndrew 2016 - Forum software by © MyBB