<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Login extends CI_Controller{
public function __construct()
{
parent::__construct();
// Your own constructor code
$this->is_logged_in();
}
function is_logged_in()
{
$is_logged_in=$this->session->userdata('is_logged_in');
if(!isset($is_logged_in) || $is_logged_in != true){
//$this->load->view('notlogin');
$this->load->view('admin_login');
//echo "you dont have permission to access this area";
}
}
function index()
{
$this->load->view('admin_login');
//die();
}
function adminlogin()
{
$this->load->model('loginmodel');
$query=$this->loginmodel->verify();
if($query==true){
$data=array(
'username'=>$this->input->post('username'),
'is_logged_in'=>true
);
$this->session->set_userdata($data);
redirect('Login/loginarea');
}
else
{
//$this->is_logged_in();
$this->index();
}
}
public function loginarea()
{
$this->load->view('mainadmin');
}
function logout()
{
$this->session->sess_destroy();
$this->index();
}
}
這裏兩個函數__construct
和index
加載相同的觀點兩次。我不會如何在邏輯上糾正這一點。我正在檢查is_logged_in
變量是否爲true:如果爲true,則加載管理員區域或其他管理員登錄頁面。但index
函數也隨之執行。多視圖正在加載驗證會話變量codeigniter
好的,謝謝......但剛纔我發現我的會議不工作,因爲當我獲取用戶名或is_logged_in數據然後沒有返回。請檢查 –