如何在 codeigniter 中检索当前记录的用户名
我需要知道当前登录的“用户名”是谁,以便在插入新文章时可以将此用户名插入数据库。
我有这个控制器来进行登录过程:
class login extends CI_Controller{
function index()
{
$this->load->view('login_form');
}
function proccess()
{
$this->load->model('membership_model');
$query = $this->membership_model->validate();
if($query) // if the user's credentials validated ..
{
$data = array(
'username_usr' => $this->input->post('username_usr'),
'is_logged_in' => true
);
$this->session->set_userdata($data);
redirect('view=dashboard');
}
else
{
$this->index();
}
}
用户登录后,我尝试像在其他控制器中一样:
echo $this->session->userdata('ip_address');
它检索IP地址,但是当尝试这个时:
echo $this->session->userdata('username_usr');
它什么也没返回。我需要检索用户名,以便在插入新文章时可以将其路径到数据库。
I need to know who is current logged in 'username' so I can insert this username into database when inserting new article.
I have this controller that make the login process:
class login extends CI_Controller{
function index()
{
$this->load->view('login_form');
}
function proccess()
{
$this->load->model('membership_model');
$query = $this->membership_model->validate();
if($query) // if the user's credentials validated ..
{
$data = array(
'username_usr' => $this->input->post('username_usr'),
'is_logged_in' => true
);
$this->session->set_userdata($data);
redirect('view=dashboard');
}
else
{
$this->index();
}
}
Once the user logged in, I try something like in other controller:
echo $this->session->userdata('ip_address');
It retrieves the ip address, but when trying this:
echo $this->session->userdata('username_usr');
it returned nothing. I need to retrieve the username so that I can path it to database while inserting new article.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方案是我调用了一个空变量,我应该通过 @silent 的评论。
The solution was that I have called an empty variable, I should rename it via @silent's comment.