我想获取已登录用户的ID,然后打印出以下行
echo "<pre>"; print_r($this->session->userdata());
结果如下:
Array
(
[__ci_last_regenerate] => 1449132599
[lang] => english
[userdata] => User_model Object
(
[table] => er_users
[primaryKey] => user_id
[primaryLabel] => user_name
[usertype] => user_type
[rules] => Array
(
[user_id] => integer
[user_type] => required|integer
[user_name] => required|min_length[3]
[user_email] => required|valid_email
[user_pass] => min_length[8]|max_length[16]
[user_pconf] => required|matches[user_pass]
[user_mobile] => required|min_length[10]
[user_avatar] =>
[user_code] => required|integer
[user_status] => required|integer
)
[forms] => Array
(
[*] => Array
(
[user_id] => Array
(
[field] => user_id
)
[user_type] => Array
(
[field] => user_type
[type] => select:hasOne[Admin/Setting][value][name^=user_type]
)
[user_name] => Array
(
[field] => user_name
)
[user_email] => Array
(
[field] => user_email
)
[user_pass] => Array
(
[field] => user_pass
[type] => password
)
[user_pconf] => Array
(
[field] => user_pconf
[type] => password
)
[user_mobile] => Array
(
[field] => user_mobile
[type] => mobile
)
[user_avatar] => Array
(
[field] => user_avatar
[type] => select:hasOne[Admin/User::avatars][avatar]
)
[user_code] => Array
(
[field] => user_code
)
[user_status] => Array
(
[field] => user_status
[type] => select:hasOne[Admin/Setting][value][name^=user_status]
)
)
[list] => Array
(
[user_id] => Array
(
)
[user_type] => Array
(
)
[user_name] => Array
(
)
[user_email] => Array
(
)
[user_mobile] => Array
(
)
[user_status] => Array
(
)
)
[search] => Array
(
[user_name] => Array
(
)
[user_email] => Array
(
)
[user_mobile] => Array
(
)
)
[create] => Array
(
[user_type] => Array
(
)
[user_name] => Array
(
)
[user_email] => Array
(
)
[user_pass] => Array
(
)
[user_mobile] => Array
(
)
[user_status] => Array
(
)
)
[edit] => Array
(
[user_id] => Array
(
[type] => hidden
)
[user_type] => Array
(
)
[user_name] => Array
(
)
[user_email] => Array
(
)
[user_pass] => Array
(
)
[user_mobile] => Array
(
)
[user_status] => Array
(
)
)
[show] => Array
(
[user_id] => Array
(
)
[user_type] => Array
(
)
[user_name] => Array
(
)
[user_email] => Array
(
)
[user_mobile] => Array
(
)
[user_status] => Array
(
)
)
[edit_account] => Array
(
[user_name] => Array
(
)
[user_email] => Array
(
)
[user_pass] => Array
(
)
[user_mobile] => Array
(
)
[user_avatar] => Array
(
)
)
[register] => Array
(
[user_name] => Array
(
)
[user_email] => Array
(
[rules] => required|valid_email|is_unique[er_users.user_email]
)
[user_pass] => Array
(
)
[user_pconf] => Array
(
)
)
[lost] => Array
(
[user_email] => Array
(
)
)
[reset] => Array
(
[user_email] => Array
(
)
[user_code] => Array
(
)
[user_pass] => Array
(
)
)
[delete] => Array
(
[user_id] => Array
(
[type] => hidden
)
)
)
[fields] => Array
(
)
[createBy] =>
[updateBy] =>
[permission] =>
[relations] => Array
(
)
[user_id] => 1
[user_type] => 1
[user_name] => Admin User
[user_email] => admin@localhost.local
[user_pass] => $2y$10$sbJV7LZNE2/1RQ5SHyeqWeOIhhU0aXgq7uXQHfID/g9K5tJLENOja
[user_mobile] =>
[user_avatar] =>
[user_code] => 0
[user_create_by] => 0
[user_update_by] => 0
[user_create_at] => 0000-00-00 00:00:00
[user_update_at] => 0000-00-00 00:00:00
[user_status] => 2
)
)
以下代码是会话设置的地方
if($auth_driver->login($input['email'], $input['password'], $input['remember']))
{
$userdata = $this->user->row(array('user_email'=>$input['email']));
// if user is not existed, create it
if (!is_object($userdata)) {
// create the user and make it active
$newuser = new User_model;
$newuser->user_type = User_model::TYPE_USER;
$newuser->user_name = $input['email'];
$newuser->user_email = $input['email'];
$newuser->user_pass = $input['password'];
$newuser->user_mobile = '';
$newuser->user_avatar = '';
$newuser->user_status = User_model::STATUS_ACTIVE;
$newuser->save();
// load the user info
$userdata = $this->user->row(array('user_email'=>$input['email']));
}
}
if(isset($userdata) && is_object($userdata) && isset($userdata->user_id)) {
// check if the account is active
if($userdata->user_status == User_model::STATUS_ACTIVE) {
$this->session->set_userdata('userdata', $userdata);
redirect('/User/Dashboard');
} else {
unset($userdata);
set_message('activate_your_account', 'error');
redirect('/Auth/Activate');
}
} else {
set_message('wrong_email_or_password', 'error');
}
redirect('/Auth/Login');
}
我希望您帮助我访问userdata中的user_id
提前致谢
答案 0 :(得分:1)
答案 1 :(得分:0)
根据您的会话转储:
$user_id = $this->session->userdata('user_id');