New to CodeIgniter, having some issues with setting session data and using it. Here's my code.
Model
Controller
View
Result
How do I access those variables in the [0] => stdClass Object? Or how do I stop them going that far in to begin with? Been fiddling it for hours but now joy. Such an annoying place to get stuck.
Any help would be greatly appreciated, thank you.
Model
PHP:
function userInfo()
{
$query = $this->db->select('first_name, last_name, email, relationship, user_level')
->from('users');
$ret['rows'] = $query->get()->result();
return $ret;
}
Controller
PHP:
function validate_credentials()
{
$this->load->model('membership_model');
$query = $this->membership_model->validate();
if($query) // If Member Validated
{
$userinfo = $this->membership_model->userInfo();
foreach ($userinfo as $key=>$value)
{
$this->session->set_userdata($key, $value);
}
$data = array ('pass' => 'true');
$this->session->set_userdata($data);
redirect(base_url());
} else {
$this->index();
}
}
View
PHP:
print_r($this->session->userdata);
Result
Code:
Array
(
[session_id] => d71e78757533c4e87c7ed05fd6f2eada
[ip_address] => 0.0.0.0
[user_agent] => Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) Ap
[last_activity] => 1287781085
[rows] => Array
(
[0] => stdClass Object
(
[first_name] => Fabien
[last_name] => Oram
[email] => [email protected]
[relationship] => Groom
[user_level] => basic
)
)
[pass] => true
)
How do I access those variables in the [0] => stdClass Object? Or how do I stop them going that far in to begin with? Been fiddling it for hours but now joy. Such an annoying place to get stuck.
Any help would be greatly appreciated, thank you.
Last edited:
