manhooei
(Alex Coner)
March 26, 2013, 2:11pm
1
After a user is logged in, I redirect them to a page which is the user area.
Now if someone has the url but isn’t logged-in (guest), then they shouldn’t
be able to access that page. Currently I put a condition on top of my page
that checks if the user is logged-in, I say if the user is guest then redirect
them to the home page. Is that how I should do it in Yii or there is a better
way of doing it ? I basically tried to mimic the way I used to do it in pure
PHP before.
I appreciate your suggestions
lalzada
(Lalzadamohmand)
March 26, 2013, 2:22pm
2
public function actionIndex() { // you want to restrict index page from users which are not logged in
if (Yii::app()->user->isGuest)
$this->actionLogin();
else
$this->redirect(array('controller/index));
}
for more
http://www.yiiframew .../en/topics.auth
manhooei
(Alex Coner)
March 26, 2013, 2:25pm
3
Thanks So instead of putting the condition on top of the view we put it in the controller action ?
lalzada
(Lalzadamohmand)
March 26, 2013, 2:32pm
4
yeah sure…because a view page is redirected/rendered from controller action…
lalzada
(Lalzadamohmand)
March 26, 2013, 2:36pm
5