Hide menu if not logged in

Hi all,

I wanted to make login page as homePage and hide menu section if not logged in.

I did the following:

main.php (layout)

 <?php if(!Yii::app()->user->isGuest): ?>

   <div id="mainMbmenu">


   </div><!-- mainmenu -->

 <?php endif;?>

In SiteController.php

	public function actionIndex()








        public function actionLogin()


		$model=new LoginForm;


			if($model->validate() && $model->login())




This works fine (as I wanted) but my question is:

Is this the correct way to do it?


You can see the use of this in default controller code.


Thank you hrnair for the answer :)

I guess I should learn how to use filters…