Reputation: 1020
I tried to load base_url()
in controller, but codeigniter does not load the helper('url')
. I also call helper from autoload
and the constructor both in the hook, but it's still not working and showing an error "Trying to get property of non-object".
Any idea how can I redirect?
My code:
if ( !defined( 'BASEPATH' ) ) exit( 'No direct script access allowed' );
class Auth_hook {
protected $CI;
public function __construct() {
$this->CI =& get_instance();
$this->CI->load->helper('url');
}
public function index(){
redirect(base_url('auth/login'));
print_r("hello!!");
if(isset($_SESSION['name']) == 'TRUE'){
redirect(base_url('auth/admin'));
}
else {
redirect(base_url('auth/login'));
}
}
}
Upvotes: 3
Views: 4355
Reputation: 6928
How about this:
class Auth_hook {
protected $CI;
public function __construct() {
$this->CI =& get_instance();
}
public function index(){
// can communicate back with CI by using $this->CI
$this->CI->load->helper('url');
redirect(base_url('auth/login'));
print_r("hello!!");
if(isset($_SESSION['name']) == 'TRUE'){
redirect(base_url('auth/admin'));
}
else {
redirect(base_url('auth/login'));
}
}
}
Upvotes: 2