0

我已经定义了这个控制器来检查用户会话:

class SessionController extends CI_Controller {

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

function dashboard_area(){
    $data['main_content'] = 'dashboardView';
    $this->load->view('dashboardTemplate/template', $data);         
}

function is_logged_in()
{
    $is_logged_in = $this->session->userdata('is_logged_in');
    if(!isset($is_logged_in) || $is_logged_in != true)
    {
        echo 'You don\'t have permission to access this page.';
        die();
        //$this->load->view('login_form');
    }
}       
    } ?>

在我的登录控制器中我这样做..

   class LoginController extends CI_Controller {

 function index(){      
    $new['main_content'] = 'loginView';
    $this->load->view('loginTemplate/template', $new);          
}   

function verifyUser(){      
    //getting parameters from view 
    $data = array(
            'username' => $this->input->post('username'),
            'password' => $this->input->post('password')
    );


    $this->load->model('loginModel'); 
    $query = $this->loginModel->validate($data);

          if ($query){             //if the user c validated
        //data variable is created becx we want to put username in session
            $data = array(
                'username' => $this->input->post('username'),
                 'is_logged_in' => true 
            );

         $this->session->set_userdata($data);
         redirect('sessionController/dashboard_area');
    }
    else
     {
        $this->index();
    }
}
function logout()
{
    $this->session->sess_destroy();
    $this->index();
}
}   
?>

现在的问题是我有很多控制器如何使用它..我不想一次又一次地制作新的会话控制器......如果在一个以上的控制器中处理会话有任何好处,那么请让我知道..我也看过这个答案...但是在应用第14个答案之后..它给了我这个错误

Fatal error: Class 'MY_Controller' not found in C:\xampp\htdocs\StockManagmentSystem\application\controllers\categoryController.php on line 4

我正在使用最新的代码点火器

4

1 回答 1

3

在扩展 CI_Controller 的 application/core 文件夹中创建一个 MY_Controller。将会话函数放在 MY_Controller 文件中,然后让其余的控制器扩展 MY_Controller 而不是 CI_Controller。

于 2013-01-11T10:37:42.387 回答