this is the function I have, in my login controller, which stores data into an array and then set the userdata
function validate_credentials()
{
$this->load->model('membership_model');
$query = $this->membership_model->validate();
if($query):
$data = array(
'username' => $this->input->post('username'),
//add usertype
//add email
//add deposit money
'is_logged_in' => true
);
$this->session->set_userdata($data);
//should redirect to last view
redirect('home/index');
else:
$this->index();
endif;
}// end of validate_credentials()
I would like to store more information like the usertype, email, depost,etc… the data is stored into the database. How do I get the data from the model to controller? or is this not recommended?
for example with the usertype I want to check in the views if the user is an admin and display certain options for admins only.
You can use the normal CI session handling done in CI.
For checking for usertype. I usually have a authentication class that checks if the user logged in is an admin. e.g.
About saving information, using the session, it is probably not the safest. I usually recommend checking for user information on the fly rather than storing everything in the CI session.