CodeIgniter Forums
Call to a member function ... on a non-object - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Call to a member function ... on a non-object (/showthread.php?tid=14681)



Call to a member function ... on a non-object - El Forum - 01-11-2009

[eluser]bigdaddysheikh[/eluser]
I am having trouble instantiating my models. I get
Code:
Call to a member function getAll() on a non-object
error even though the same model works in other controllers.

here is my controller that is calling the model.

Code:
<?php

class Welcome extends Controller {
    function Weclome()
    {
        parent::Controller();    
        $this->load->helper(array('form','url'));
        $this->load->database();    
        $this->load->model("pages");
    }
    
    function index()
    {
        $data["listing"] = $this->pages->getAll();
        $this->load->view("index", $data);
    }
}

here is the model:
Code:
<? class Pages extends Model {

    var $title   = '';
    var $content = '';
    var $date    = '';

    function Pages()
    {
        // Call the Model constructor
        parent::Model();
        $this->load->helper('form');        
    }
    
    function getAll()
    {
        $query = $this->db->get('page');
        return $query->result();
    }

What can be the problem? The same model and lines work in my other admin controllers.

Thanks in advance for helping.


Call to a member function ... on a non-object - El Forum - 01-11-2009

[eluser]bigdaddysheikh[/eluser]
here is a weird fix.

I change the name of the controller from "welcome.php" to "home.php" and now it works.

This is the most weirdest bug.


Call to a member function ... on a non-object - El Forum - 01-12-2009

[eluser]jalalski[/eluser]
It's not a bug, it's doing what it is supposed to do... Smile

Look at the Codeigniter documentation, especially the part about naming of your Model classes.


Call to a member function ... on a non-object - El Forum - 01-12-2009

[eluser]sophistry[/eluser]
you have a typo in the original post code Weclome !== Welcome


Call to a member function ... on a non-object - El Forum - 01-12-2009

[eluser]bigdaddysheikh[/eluser]
Oh my,

how silly of me. I feel embarrassed :$:$. Simple proof reading.

Thank you very much.