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

[eluser]BigBonsai[/eluser]
Hello,

I have been struggling to get my bearings on CI now for a few days. Things have gone fairly well. I have overcome the dust on the user guide (some outdated stuff in there) and now I am thoroughly stuck. After reading this forum for two hours I still cannot get anywhere, although this problem has been discussed before. I guess my understanding of OOP is not good enough. Well, let's see. This is my error message:

Code:
Fatal error: Call to a member function login() on a non-object in [...]\application\controllers\pages.php on line 46

Ok. So here is "pages.php":

Code:
<?php

class Pages extends CI_Controller {

    public $data = array('subview' => 'Oops... no subview');

    public function __construct() {
parent::__construct();
session_start();
$this->load->helper('url');
$this->load->helper('language');
$this->load->language('general', 'german');
    }

    [...]

    public function signin() {
$this->load->helper('form');
$this->load->library('Form_validation');

$this->form_validation->set_rules('login_nick', 'Nick', 'required');
$this->form_validation->set_rules('login_password', 'Password', 'required');

if ($this->form_validation->run() === FALSE) {
     $this->data['subview'] = 'signin';
     $this->load->view('layouts/layout', $this->data);
} else {
     $this->login_model->login();
     $this->data['subview'] = 'success';
     $this->load->view('layouts/layout', $this->data);
}
    }

}

The problem is this line:
Code:
$this->login_model->login();
And finally the model file "login_model.php":

Code:
<?php

class Login_model extends CI_Model {

    function login($nick = '', $password = '') {
//Put here for PHP 4 users
$this->CI = & get_instance();

//Make sure login info was sent
if ($nick == '' OR $password == '') {
     return false;
}

//Check if already logged in
if ($this->CI->session->userdata('user_nick') == $nick) {
     //User is already logged in.
     return false;
}

//Check against user table
$this->CI->db->where('user_nick', $nick);
$query = $this->CI->db->get_where($this->user_table);

if ($query->num_rows() > 0) {
     $row = $query->row_array();

     //Check against password
     if (hash("512", $password) != $row['user_pw']) {
  return false;
     }

     //Destroy old session
     $this->CI->session->unset_userdata();

     //Create a fresh, brand new session
     $this->CI->session->sess_create();

     //Remove the password field
     unset($row['user_pw']);

     //Set session data
     $this->CI->session->set_userdata($row);

     //Set logged_in to true
     $this->CI->session->set_userdata(array('online' => true));

     //Login was successful
     $_SESSION['logged_in'] = 1;
     return true;
} else {
     //No database result found
     $_SESSION['logged_in'] = 0;
     return false;
}
    }

}

As you can see (for whoever knows it), the login function is copied from the Simplelogin library, but ultimately I suspect it doesn't matter what it says in there, since it is not accessed in the first place.

The database connection is not included, because I have this line in the autoconfig.php:

Code:
$autoload['libraries'] = array('database', 'session');

In my humble understanding, this should take care of the database connection.

What am I overlooking/messing up for getting the above mentioned error?

Thanks a bundle in advance! Smile


BiB


Messages In This Thread
Call to a member function ... on a non-object - by El Forum - 04-14-2012, 07:33 AM
Call to a member function ... on a non-object - by El Forum - 04-14-2012, 08:14 AM
Call to a member function ... on a non-object - by El Forum - 04-14-2012, 08:20 AM
Call to a member function ... on a non-object - by El Forum - 04-14-2012, 08:32 AM
Call to a member function ... on a non-object - by El Forum - 10-06-2012, 03:30 AM
Call to a member function ... on a non-object - by El Forum - 10-06-2012, 04:14 AM
Call to a member function ... on a non-object - by El Forum - 10-06-2012, 06:03 AM
Call to a member function ... on a non-object - by El Forum - 10-06-2012, 08:23 AM
Call to a member function ... on a non-object - by El Forum - 03-12-2014, 01:38 PM



Theme © iAndrew 2016 - Forum software by © MyBB