i want to give access only to the authorized users
so i wrote the authentication code in the construct method
here is my code
class cp extends CI_Controller {
public function __construct(){
parent::__construct();
$this->this_mustbe_admin();
}
public function this_mustbe_admin()
{
$this->load->model('m_cp');
$md = $this->m_cp->is_admin();
if($md)
return $md;
else
{
redirect(base_url().'cp/login/');
}
}
function login()
{
$this->load->view('admin/login');
}
but i get error
The page isn't redirecting properly
if i remove this_mustbe_admin method from construct and put it on the other controllers it works fine
function do_stuff(){
$this->this_mustbe_admin();
// do stuff
}
but this way i have to write it in each and every one of my methods
You doing circular redirection. An imaginary stack trace:
/cp/__construct()this->this_mustbe_admin()-> redirect to /cp/login/cp/login__construct()this->this_mustbe_admin()-> GOTO 3.You will have to check what method you are trying to execute in your
__constructbefore doing the redirection generating command.