【问题标题】:Disable ion auth for front end in codeigniter在 codeigniter 中禁用前端的 ion auth
【发布时间】:2018-05-26 08:30:21
【问题描述】:

我已经尝试了一段时间,但没有结果.. 我在我的 codeignitor 网站中使用了 ion auth。

我想为前端登录禁用 ion auth,并希望它仅适用于管理端登录。那可能吗?如果是,那么如何..

我的代码:

    class Login extends MY_Controller {

        public function __construct(){
        parent::__construct();
        $this->load->library('session');
        $this->load->helper('url');
        require_once APPPATH.'vendor/autoload.php';
        }

        public function index(){

            $this->render('login');

        }
}

这会产生以下错误:

A PHP Error was encountered

Severity: Notice

Message: Undefined property: CI::$ion_auth

Filename: MX/Controller.php

Line Number: 59

Backtrace:

File: D:\xampp\htdocs\moneyclues2\application\third_party\MX\Controller.php
Line: 59
Function: _error_handler

File: D:\xampp\htdocs\moneyclues2\application\core\MY_Controller.php
Line: 126
Function: __get

File: D:\xampp\htdocs\moneyclues2\application\core\MY_Controller.php
Line: 59
Function: _setup

File: D:\xampp\htdocs\moneyclues2\application\controllers\Login.php
Line: 7
Function: __construct

File: D:\xampp\htdocs\moneyclues2\index.php
Line: 316
Function: require_once

当我扩展 CI_controller.渲染方法出现以下错误

Fatal error: Call to undefined method Login::render() in D:\xampp\htdocs\moneyclues2\application\controllers\Login.php on line 15
A PHP Error was encountered

Severity: Error

Message: Call to undefined method Login::render()

Filename: controllers/Login.php

Line Number: 15

Backtrace:

【问题讨论】:

  • 在构造函数顶部获取 Codeigniter 实例:$this->CI =& get_instance();
  • 抱歉@Vickel 对我不起作用。再次显示相同的错误。

标签: codeigniter ion-auth


【解决方案1】:

将 ion_auth 库 $autoload['libraries'] = array('database','ion_auth'); 添加到 autoload.php 对我有用。

并扩展 MY_Controller 代替 CI_Controller。

【讨论】:

    【解决方案2】:

    您需要加载Ion_Auth 库! $this->load->library('ion_auth');

    但是,如果您希望它仅用于与管理相关的内容,只需在 core 中创建两个不同的 MY 控制器,并让您的公共和管理控制器扩展它们。如果您只在网站的 1/2 中使用 Ion_Auth,请不要自动加载它。

    class MY_Public_Controller extends CI_Controller {
    
        public function __construct() {
            parent::__construct();
            // load what you need here
        }
    
    }
    
    class MY_Admin_Controller extends CI_Controller {
    
        public function __construct() {
            parent::__construct();
            // load what you need here
            $this->load->database();
            $this->load->library('session');
            $this->load->library('ion_auth');
        }
    
    }
    

    示例管理控制器:

    class Somecontroller extends MY_Admin_Controller {
    
        public function index() {
    
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 2013-02-11
      • 1970-01-01
      • 2011-10-12
      • 2019-03-11
      • 1970-01-01
      • 1970-01-01
      • 2012-05-30
      • 1970-01-01
      • 2016-01-23
      相关资源
      最近更新 更多