无法在 codeigniter 中加载 url 助手
Can not load url helper in codeigniter
我试图在控制器中加载 base_url()
,但 codeigniter 没有加载 helper('url')
。我还在钩子中调用了 autoload
的帮助程序和构造函数,但它仍然无法正常工作并显示错误 "Trying to get property of non-object".
知道如何重定向吗?
我的代码:
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'));
}
}
}
这个怎么样:
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'));
}
}
}
我试图在控制器中加载 base_url()
,但 codeigniter 没有加载 helper('url')
。我还在钩子中调用了 autoload
的帮助程序和构造函数,但它仍然无法正常工作并显示错误 "Trying to get property of non-object".
知道如何重定向吗?
我的代码:
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'));
}
}
}
这个怎么样:
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'));
}
}
}