我有一个模型:
<?php
class Loginfunctionmodel extends CI_Model{
function __construct()
{
// Call the Model constructor
parent::__construct();
}
# check_if_loggedin() below checks if user has session w/ loggedIn=1, then displays needed supernav elements
function check_if_loggedin(){
$this->load->library('session');
# user has loggedin Val = 1 and valid session_id
$loggedInSetSuccess = 1;
$sess = $this->session->userdata('session_id');
$sessionsDbCompare = $this->db->get_where('Client',array('session_id'=>$sess,'loggedIn'=>$loggedInSetSuccess));
// no session id for user in database... load login
if($sessionsDbCompare->num_rows() == 1 ){
$this->load->view('supernavigationloggedin.php');
$this->load->view('primarynavigation.php');
}
// otherwise problem with session count for the user is greater than 1.
// Regenerate values
elseif($sessionsDbCompare->num_rows() > 1){
#remove current errorneous [session_id] data
$this->session->unset_userdata();
#reset [session_id] data
$this->session->set_userdata();
# load logged in views, given single session id exists.
$this->load->view('supernavigationnotloggedin.php');
$this->load->view('primarynavigation.php');
}
// otherwise problem with session or loggedIn ... show login form.
else{
#remove current errorneous [session_id] data; load not logged in views.
$this->session->unset_userdata();
$this->load->view('supernavigationnotloggedin.php');
$this->load->view('primarynavigation.php');
}
}
}
?>
问题是当我访问这个页面时@localhost/mysite
它会加载以下视图:homepage.php
并且这个模型(上面)homepagemodel.php
也调用了加载,但是一旦我加载页面就会创建一个会话,我如何让它只if{} block
被执行?如果我把它放在里面,if{} block
那么使用$this->load->library('session');
.
任何人?我一直在为此尝试各种修复,但它会不断使用重复的会话值制作重复的行