无法在codeigniter中加载url helper

时间:2016-08-07 08:09:39

标签: php codeigniter helper

我尝试在控制器中加载base_url(),但codeigniter不会加载helper('url')。我也从autoload和构造函数中调用帮助程序,但是它仍然无效并显示错误"试图获取非对象的属性"。

我知道如何重定向?

我的代码:

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'));
      }
    }
}

1 个答案:

答案 0 :(得分:2)

这个怎么样:

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'));
    }
  }
}