找不到MY_Controller类 [英] MY_Controller class not found

查看:551
本文介绍了找不到MY_Controller类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想解决的主要是当有人想访问管理面板时检查用户会话。我已经创建了MY_Controller类并将其放在库中。

 类MY_Controller扩展了CI_Session {

public $ logged_in = FALSE;

public function __construct(){
parent :: __ construct();
$ this-> is_logged_in();
}

public function is_logged_in()
{
$ logged = $ this-> userdata('user_id');
$ this-> logged_in =($ logged)?真假;
}

function sessdestroy(){

$ this-> session-> sess_destroy();

}

}

登录页面。我创建了一个重定向到管理面板(信息中心)的按钮,只是为了测试会话检查是否有效。

  CI_Controller {

function __construct(){

parent :: __ construct();

}

public function index(){

$ this-> load-> view('view_login');

if(isset($ _ POST ['redirect'])){

redirect('admin');

}
}


}


b $ b

这是管理控制器,我检查用户会话是否存在。

  class Admin extends MY_Controller {

function construct(){

parent :: __ construct();

}


function index(){

if($ this-> is_logged_in()){

$ this-> dodadi_destinacija();

}

else redirect('login');

}

}

此错误。

 致命错误:在C:\wamp\www\UserPanel\中找不到类'MY_Controller' application\controllers\admin.php on line 3 

你能告诉我你对我的编码的想法解决方案:

解决方案


  1. 您需要扩展 CI_Controller class CI_Session

  2. 您应该将 MY_Controller 下的应用程序/ core / 文件夹而不是应用程序/库 / ol>

    The main thing i want to solve is to check user session when somebody want to access admin panel. I've created MY_Controller class and placed it in library.

    class MY_Controller extends CI_Session {
    
    public $logged_in = FALSE;
    
    public function  __construct() {
        parent::__construct();
        $this->is_logged_in();
    }
    
    public function is_logged_in()
    {
        $logged = $this->userdata('user_id');
        $this->logged_in = ($logged) ? TRUE : FALSE;
    }
    
    function sessdestroy() {
    
        $this->session->sess_destroy();
    
    }
    
    }
    

    This is my login page. I've created a button that redirects to admin panel (dashboard) just to test if the session check works.

    class Login extends CI_Controller {
    
    function __construct() {
    
        parent::__construct();
    
    }
    
    public function index() {
    
        $this->load->view('view_login');
    
        if(isset($_POST['redirect'])) {
    
        redirect('admin');
    
        }
    }
    
    
    }
    

    This is the admin controller where i check if the user session exists.

    class Admin extends MY_Controller {
    
    function construct() {
    
        parent::__construct();
    
    }
    
    
    function index() {
    
        if($this->is_logged_in()) {
    
        $this->dodadi_destinacija();
    
        }
    
        else redirect('login');
    
    }
    
    }
    

    BUT i got this error.

    Fatal error: Class 'MY_Controller' not found in C:\wamp\www\UserPanel\application\controllers\admin.php on line 3
    

    Can you tell me your thoughts about my coding solution for the given problem please :)

    解决方案

    1. You need to extend the CI_Controller class instead of CI_Session
    2. You should place MY_Controller under application/core/ folder instead of application/library

    这篇关于找不到MY_Controller类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆