CodeIgniter Forums
Error - "Call to a member function on a non-object" - Any ideas? - 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: Error - "Call to a member function on a non-object" - Any ideas? (/showthread.php?tid=28020)



Error - "Call to a member function on a non-object" - Any ideas? - El Forum - 02-27-2010

[eluser]invision[/eluser]
Hi,

I'm getting this error on this function:

"Call to a member function on a non-object".

I have marked in the code where the issue arises.


Code:
<?php
class MPages extends Model{

    function MPages(){
        parent::Model();
    }

    function getPageBySlug($slug){
        $data = array();
        **** $this->db->where('slug',$slug); ****
        $this->db->limit(1);
        $Q = $this->db->get('pages');
        if ($Q->num_rows() > 0){
          $data = $Q->row_array();
        }
        $Q->free_result();    
        return $data;    
    }

I'd love to get some help with this. Planned to make a decent dent on a project today and fallen at the first Sad


Many thanks for any ideas.


Error - "Call to a member function on a non-object" - Any ideas? - El Forum - 02-27-2010

[eluser]JoostV[/eluser]
Try loading the database class.
Code:
$this->load->database();



Error - "Call to a member function on a non-object" - Any ideas? - El Forum - 02-27-2010

[eluser]invision[/eluser]
Many thanks Joost! All sorted now.