Welcome Guest, Not a member yet? Register   Sign In
Community auth not working
#8

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
Reply


Messages In This Thread
Community auth not working - by rakibtg - 06-26-2015, 04:39 AM
RE: Community auth not working - by skunkbad - 06-26-2015, 07:24 AM
RE: Community auth not working - by rakibtg - 06-26-2015, 08:24 AM
RE: Community auth not working - by skunkbad - 06-26-2015, 01:38 PM
RE: Community auth not working - by rakibtg - 06-27-2015, 02:50 AM
RE: Community auth not working - by skunkbad - 06-27-2015, 11:29 AM
RE: Community auth not working - by rakibtg - 06-28-2015, 09:40 AM
RE: Community auth not working - by skunkbad - 06-28-2015, 10:01 AM
RE: Community auth not working - by vsuri - 08-08-2015, 12:18 AM
RE: Community auth not working - by skunkbad - 08-08-2015, 09:59 PM
RE: Community auth not working - by skunkbad - 08-09-2015, 08:51 AM
RE: Community auth not working - by skunkbad - 08-09-2015, 02:24 PM
RE: Community auth not working - by vsuri - 08-09-2015, 07:14 PM
RE: Community auth not working - by ethan sohail - 01-18-2016, 07:38 AM
RE: Community auth not working - by skunkbad - 01-18-2016, 08:22 PM



Theme © iAndrew 2016 - Forum software by © MyBB