Reputation: 283
In CodeIgniter, checking if an input exists is easy.
Rather than using
$something = isset($_POST['something']) ? $_POST['something'] : NULL;
You can simply do:
$something = $this->input->post('something');
My question is, is it the same with session?
$something = isset($_SESSION['something']) ? $_SESSION['something'] : NULL;
the same with
$something = $this->session->something;
Upvotes: 1
Views: 2757
Reputation: 543
Yes, $this->session->something
will work just fine.
Just remember to load the library. And read the manual if you like:
Upvotes: 1
Reputation: 6994
Check whether session variable is set or not using $this->session->has_userdata('variable');
so try like this..
$something = $this->session->has_userdata('something')? $this->session->userdata('something') : NULL;
if session variable is not set then
$something
hasNULL
value otherwise it has session value.
For more see codeigniter session
Upvotes: 1