【问题标题】:Can not load url helper in codeigniter无法在 codeigniter 中加载 url helper
【发布时间】:2016-12-13 05:24:18
【问题描述】:

我试图在控制器中加载base_url(),但codeigniter 没有加载helper('url')。我还从 autoload 和钩子中的构造函数中调用了 helper,但它仍然无法正常工作并显示错误“尝试获取非对象的属性”。

知道如何重定向吗?

我的代码:

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

【问题讨论】:

  • 只加载一次。我建议将其从挂钩中删除并仅将其放入 FCPATH.'config/autoload.php' 文件中。如果您不使用预系统挂钩。否则,首先加载APPPATH.'config/autoload.php'

标签: php codeigniter helper


【解决方案1】:

这个怎么样:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-13
    • 2015-05-28
    • 1970-01-01
    • 2022-07-05
    • 2014-01-29
    • 1970-01-01
    • 2011-06-14
    相关资源
    最近更新 更多