0

I create simple library called Xauth.php to check if user already login or not:

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

class Xauth
{
  protected $ci;

  public function __construct()
  {
    $this->ci =& get_instance();
  }

  public function is_logged_in()
  {
    if ($this->ci->session->userdata('is_logged_in'))
    {
      return true;
    }

    return false;
  }
}

I put that library in my Admin_Controller, so whatever controller extended with Admin_Controller will be checked first, if the session data is empty they will be redirect to login page. And this is my Admin_Controller.php:

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

class Admin_Controller extends MY_Controller {

  public function __construct()
  {
    $this->load->library('Xauth');

    if ($this->Xauth->is_logged_in() == false) {
      redirect('auth');
    }
  }

}

But I got an errors, it says:

Message: Undefined property: Dashboard::$Xauth

Where is my fault?

1 Answer 1

1

You must use your class with lowercase letters :

$this->xauth->is_logged_in()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.