First, look at the Examples controller. Like the Examples controller, your controller needs to extend MY_Controller. MY_Controller, which should now be in your application/core directory needs to have been copied from the community_auth/core directory. This is part of the installation instructions.
Now that you have your controller set up to use Community Auth, consider this:
Code:
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Foo extends MY_Controller
{
public function __construct()
{
parent::__construct();
}
// -----------------------------------------------------------------------
public function index()
{
if( $this->require_role('admin') )
{
// Admin is logged in! No need to call is_logged_in().
// Auth related variables have
// been loaded in Auth_Controller. These variables are
// available as Class properties in your controller,
// view variables in your views, or config items anywhere.
$this->load->view('template/header', [
'title' => 'Welcome Admin'
]);
}
}
// -----------------------------------------------------------------------
public function bar()
{
// This method does not require login,
// but we use is_logged_in to make vars available
$this->is_logged_in();
// If user is logged in, auth related variables have
// been loaded in Auth_Controller. These variables are
// available as Class properties in your controller,
// view variables in your views, or config items anywhere.
$this->load->view('template/header', [
'title' => 'Welcome'
]);
}
// -----------------------------------------------------------------------
}
Take a look at the _set_user_variables() method in Auth_Controller to see the variables that are available for you to use. Also, the Community Auth documentation shares this information:
http://community-auth.com/documentation/...-variables