问题
I have a controller named admin,and all functions in the controller can be used if the session variable is set,so what are the best ways to check if the session is set ,when clicking each link in the page or reloading the pages...
for example: if i open my admin home page in multiple tabs in a browser and sign off from first tab, bt after that in the second tab all links a working properly
so i want to check if the session is set or not...
Thanks!
回答1:
If you want to check whether the session variable is set or not, then use this.
if($this->session->userdata('session_variable')) {
// Do your code here
}
Meanwhile, if you want to check whether the session variable is set with a particular value, then you can use this.
if($this->session->userdata('session_variable') == "VALUE") {
// Do your code here
}
回答2:
According to http://ellislab.com/codeigniter/user-guide/libraries/sessions.html "Retrieving Session Data",
$this->session->userdata('not_set')
returns false.
回答3:
Simple join query solve your issue.
$this->db->select('*');
$this->db->from('first_table_name ftn');
$this->db->join('second_table_name stn', 'ftn.id = stn.id','left');
$query = $this->db->get();
来源:https://stackoverflow.com/questions/14556194/codeigniter-checking-session-variable-is-already-set-or-not-when-clicking-each-l