show logout button along with the name of user after successfull login

余生长醉 提交于 2019-12-20 07:41:19

问题


I am a yiibie, and i am stuck at a point. I have three roles in my project. 1.Admin. 2.Owner 3. Authenticated User. I have a header and a footer widget.In header widget which is the top section has a signup and login link. i want to show my user name and a logout link after his successful login. I do not want to make another widget. i Know the logic, we can use if else. If a user has been logged in, show his name and logout link at the top section(header widget). else if he is a normal user or not logged in show him, signup and login link. Thats it.But how to write code..is the thing i dont know. Plus i am using yii rights and yii user extension too.


回答1:


Read the documentation please.

This will be helpful:

http://www.yiiframework.com/doc/api/1.1/CWebUser#isGuest-detail

Here example: http://pastebin.com/r0XpkPNZ




回答2:


Is easy after login you can see the username otherwise you see nothings

<?php  
   if (!Yii::app()->user->isGuest) {
    echo Yii::app()->user->name;
   }
 ?>


来源:https://stackoverflow.com/questions/32272633/show-logout-button-along-with-the-name-of-user-after-successfull-login

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