Welcome Guest, Not a member yet? Register   Sign In
Call to a member function ... on a non-object

I am having trouble instantiating my models. I get
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.


class Welcome extends Controller {
    function Weclome()
    function index()
        $data["listing"] = $this->pages->getAll();
        $this->load->view("index", $data);

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

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

    function Pages()
        // Call the Model constructor
    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.

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.

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.

you have a typo in the original post code Weclome !== Welcome

Oh my,

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

Thank you very much.

Theme © iAndrew 2016 - Forum software by © MyBB