Allowing Only Logged In Users To See A Page. Is This How To Do It ?

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 :)


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

Thanks :) So instead of putting the condition on top of the view we put it in the controller action ?

yeah sure…because a view page is redirected/rendered from controller action…

for more about a view rendering/redirecting

http://www.yiiframework.com/doc/guide/1.1/en/basics.view