Hi ben,
I have downloaded the latest version of ion auth and using it for my application. I have a small doubt regardign ion auth. it is very easy to use in my application.
https://github.com/benedmunds/CodeIgniter-Ion-Auth
Could you please give me suggestion that i have to create site admin panel using ion auth.
my folder structure will be
controller
admin
dashboard.php
pages.php
........ etc
I am going to create many controller like this using ion auth. is it secure to check whether the user is admin or member group like this in constructor of every controller or is it wrong to check like this and also can we rename auth to admin?
if (!$this->ion_auth->is_admin()) {
redirect(‘home’);
}
Please advise on this
You can create MY_controller in core folder and extend CI_Controller, in that file i usually create 3 class. MY_controller, Admin_controller and Public_controller. example:
<?php defined('BASEPATH') OR exit('No direct script access.');
class MY_Controller extends CI_Controller {
public $data = array();
public function __construct()
{
// do some stuff here that affects all controllers
}
}
class Public_Controller extends MY_Controller {
public function __construct()
{
parent::__construct();
$this->data['meta_title'] = "My Awesome Website";
}
}
class Admin_Controller extends MY_Controller {
public function __construct()
{
parent::__construct();
$this->data['meta_title'] = "Admin Panel My Awesome Website";
$this->load->library('ion_auth');
// Check if admin is logged in
if (!$this->ion_auth->is_admin()) {
redirect(‘home’);
}
}
}
Just extend Admin_Controller class for every admin controller you will create, instead of type/copy paste that code in every admin controller.. sorry for my bad english, cheers 😊