Welcome Guest, Not a member yet? Register   Sign In
writing a library that uses other libraries
#1

[eluser]dadamssg[/eluser]
I'm trying to write a library that holds a function that simply checks if the user is logged in or not and return true/false. I need to load the session library in my library. I referenced the session class like the user guide says but it still isn't being referenced right. I still have an error on the line i'm setting $username with. Any see what im doing wrong?

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

class Loginclass {

    public function logged_in()
    {
        $CI =& get_instance();
        $CI->load->library('session');
        
        $username = $this->session->userdata('username');
        $logged_in = $this->session->userdata('logged_in');
        if(empty($username)){$value = FALSE;}
        elseif(!is_numeric($username)){$value = FALSE;}
        elseif($logged_in !== TRUE){$value = FALSE;}
        else{$value = TRUE;}
        return $value;
    }
}

?>

my relavent controller function
Code:
public function log()
    {
        $this->load->library('loginclass');
        if($this->loginclass->logged_in())
        {
            echo "You are logged in.";
        }
        else
        {
            echo "You are not logged in.";
        }
    }


Messages In This Thread
writing a library that uses other libraries - by El Forum - 06-29-2011, 09:17 AM
writing a library that uses other libraries - by El Forum - 06-29-2011, 09:26 AM
writing a library that uses other libraries - by El Forum - 06-29-2011, 09:26 AM



Theme © iAndrew 2016 - Forum software by © MyBB