get logged in user info in CodeIgniter (HMVC & Ion Auth)

女生的网名这么多〃 提交于 2020-01-03 03:44:09

问题


I am trying to get Logged in user details in CodeIgniter (HMVC & Ion Auth)

$data['user'] = $this->ion_auth->user()->row();

When i try to display i am getting error

Undefined variable: user

I am not sure how to get loggin in user id or email. I need id or email. Please help


回答1:


If your are trying to display it in view,

Are you passing the $data variable to the view ?

$data['user']=$this->ion_auth->user()->row();
$this->load->view("filename",$data);

If you are trying to access it with the controller you can access the variable like

$data['user']=$this->ion_auth->user()->row();
$username=$data['user']->username;

Please specify where you are initializing it and where you are accessing it.




回答2:


I will say one example. Follow this example may be it will help you.

Suppose you have a login form with Email and Password fields. When you submitted that form it will check whether you submitted properly with validation errors and everything. If everything is okay. It will check whether it is valid email and password match from database. If that also true than those email and username will save to session data in model of MVC design pattern. Once when you succeeded you just need to retrieve user information from that session data in controller and you need pass that data in an array to the next page after login.

$logged_in = $this->session->userdata("logged_in_user");


来源:https://stackoverflow.com/questions/12929113/get-logged-in-user-info-in-codeigniter-hmvc-ion-auth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!