Welcome Guest, Not a member yet? Register   Sign In
Session Library not loaded in extended controlloer
#1

[eluser]Cally[/eluser]
Hello all,

First time posting here and loving the CodeIgniter framework.
I have been extending the standard controller with a bunch of methods that make page to page execution easier and more convenient but I've run in to a snag with one of them.

For some reason, the extended controller can't find the models/libraries on certain pages and throws up this error:

Severity: Notice
Message: Undefined property: B2_Controller::$User
Filename: libraries/Loader.php
Line Number: 1035

What puzzles me is that they are loaded in the contructor before anything is executed as well as autoloaded before execution even starts (debugging attempt) so why are they undefined? I tried to load the CI base as a reference in to the constructor with get_instance but didn't have much luck their either.

I don't usually come asking for help as I can often find the answers some where on this forum. Smile

Anyway, I'll post the contructor and the methods that seem to be related.

Code:
class B2_Controller extends Controller {

    public function B2_Controller() {
        parent::Controller();
        $this->load->model("User_model", "User");
        $this->load->library("session");
        $this->defaultLinks();
        $this->defaultMenus();
        $this->defaultJavascriptVars();
        $this->rememberLog();
    }

    protected function setSession($Username, $Password, $Remember = false) {
        $cUser = $this->User->checkUser($Username, $Password);
        if($cUser) {
            $this->session->set_userdata(array('user_id' => $cUser['user_id'], 'user_name' => $cUser['user_name'], 'user_password' => $cUser['user_password']));
            if($Remember) {
                set_cookie('username', $Username, 31536000, '.192.168.1.4', '/');
                set_cookie('password', $Password, 31536000, '.192.168.1.4', '/');
            }
            return true;
        } else return false;
    }

    protected function unsetSession() {
        $this->session->unset_userdata(array('user_id' => '', 'user_name' => '', 'user_password' => ''));
        delete_cookie("username");
        delete_cookie("password");
    }

    protected function isLoggedIn() {
        if($this->session->userdata('user_id') && $this->session->userdata('user_name') && $this->session->userdata('user_password')) {
            $cUser = $this->User->checkUser($this->session->userdata('user_name'), $this->session->userdata('user_password'));
            if($cUser) return true;
        }
        return false;
    }

    protected function rememberLog() {
        if(!$this->isLoggedIn()) {
            $Username = get_cookie("username");
            $Password = get_cookie("password");
            if($Username && $Password) {
                if($this->User->checkUser($Username, $Password))
                $this->setSession($Username, $Password, true);
                else $this->unsetSession();
            }
        }
    }



}


Messages In This Thread
Session Library not loaded in extended controlloer - by El Forum - 11-30-2010, 06:29 AM
Session Library not loaded in extended controlloer - by El Forum - 11-30-2010, 06:59 AM
Session Library not loaded in extended controlloer - by El Forum - 11-30-2010, 07:03 AM
Session Library not loaded in extended controlloer - by El Forum - 11-30-2010, 08:04 AM
Session Library not loaded in extended controlloer - by El Forum - 11-30-2010, 02:02 PM
Session Library not loaded in extended controlloer - by El Forum - 11-30-2010, 10:09 PM
Session Library not loaded in extended controlloer - by El Forum - 12-01-2010, 09:46 PM



Theme © iAndrew 2016 - Forum software by © MyBB