Welcome Guest, Not a member yet? Register   Sign In
how to specify instance in library
#1

[eluser]elmne[/eluser]
I have a function like this in the library


Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Auth {

    var $CI = null;

    function Auth()
    {
        $this->CI =& get_instance();

        $this->load->library('session');
        $this->load->database();
        $this->load->helper('url');
    }

    function process_login($login = NULL)
    {
        // A few safety checks
        // Our array has to be set
        if(!isset($login))
            return FALSE;
    
        //Our array has to have 2 values
        //No more, no less!
        if(count($login) != 2)
            return FALSE;
    
        $username = $login[0];
        $password = $login[1];


When i run the process, i get this error

Quote:A PHP Error was encountered
Severity: Notice

Message: Undefined property: Auth::$load

Filename: libraries/auth.php

Line Number: 11


Line 11 is this

Code:
9    $this->CI =& get_instance();
       10  
       11    $this->load->library('session');

Therefore i seem to have a problem with the "get_instance"

how am i supposed to specify it to work?

The source for this is a login tutorial at

www.bramme.net/2008/07/auth-library-for-codeigniter-tutorial/
#2

[eluser]packetfox[/eluser]
I do it this way:

Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Someclass {

    // get the CI Super object
    function __construct(){
        $this->CI =& get_instance();
    }

    function some_function(){
// eg. now $this->CI->session etc works

    }

}
#3

[eluser]Buso[/eluser]
Code:
$this->CI->load->library('session');
#4

[eluser]packetfox[/eluser]
Well yes, loading it first of course. I autoload most of my commonly used Libs, so its not needed;
#5

[eluser]elmne[/eluser]
Thanks




Theme © iAndrew 2016 - Forum software by © MyBB