Welcome Guest, Not a member yet? Register   Sign In
undefined property
#1

[eluser]f0n3man[/eluser]
i am having a problem getting an error message from the controller that the property Site::$site_model is undefined. the php error in the system log states: 'Call to a member function get_records() on a non-object in /path/etc...'. the get_records function exists in site_model.php. i have the database library autoloaded, and even have the model loaded in the controller, and still get the same error message. i have done this in two different installations with 2 different versions. i can access the database and pull records. from the controller. i am brand new to codeigniter, but so far am not impressed as i can't get it to work properly. any other ideas?
#2

[eluser]OliverHR[/eluser]
Do yo call parent::Controller in your class constructor??

Post your code.
#3

[eluser]f0n3man[/eluser]
Most of this code came from one of the wiki tutorials. I modified it in attempts to make it work. The controller is:
Code:
class Site extends Controller
{
    
    function Site()
    {
        parent::Controller();
        $this->load->helper('url');
        $this->load->helper('form');
        $this->output->enable_profiler(TRUE);
    }
    
    function index()
    {
        $data['records'] = $this->site_model->get_records();
        $this->load->view('site_view', $data);
    }
and the model is:
Code:
class Site_model extends Model {
    
function Site_model()
    {
        // Call the Model constructor
        parent::Model();
        $this->load->database();
    }
    
    function get_records()
    {
        $query = $this->db->get('data');
        return $query->result();
    }

Since I'm absolutely new to OOP programming, I'm guessing it's something simple.
#4

[eluser]Twisted1919[/eluser]
And where do you load your model ?
Should be :
Code:
function Site()
    {
        parent::Controller();
        $this->load->helper('url');
        $this->load->helper('form');
        $this->load->model('site_model');
        $this->output->enable_profiler(TRUE);
    }
#5

[eluser]f0n3man[/eluser]
That line is actually in the current itteration and still gets the same message. I have been scouring the forums looking for answers to this, and have added and deleted lines and have installed CI on 2 different servers all with the same results. When I fool with some of the settings in the configuration files, I either get Fatal Errors, or messages from CI that things aren't right. I haven't had this much trouble with an application in quite a while.
#6

[eluser]danmontgomery[/eluser]
Linux or Windows? Is the file named correctly?
#7

[eluser]f0n3man[/eluser]
It is on a Linux server, and I have double checked spelling and case everywhere.
#8

[eluser]InsiteFX[/eluser]
Did you try autoloading the database in application/config/autoload.php ?

InsiteFX
#9

[eluser]f0n3man[/eluser]
yes, and loading it the model construct at one point.
#10

[eluser]InsiteFX[/eluser]
Try loading the database in your Controller.

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB