Init Login Before View Website

I want people to want to visit my site, must first login. I do the following:

(file Controller Components:)


class Controller extends CController

{

	public $layout='//layouts/main';

	public $menu=array();

	public $breadcrumbs=array();


	public function init()

	{

		if($error=Yii::app()->errorHandler->error)

		{

			if(Yii::app()->request->isAjaxRequest)

				echo $error['message'];

			else

			{

				$this->layout='//layouts/login';

				$this->render('error',$error);

			}

		}

		else

		{

			if(Yii::app()->user->isGuest)

			{

				$this->layout='//layouts/login';

				$this->render('login');

			}

		}

	}

}

check to see when not logged, the system renders the login page and index page (or a page) who can help me either only render?

why are you doing like this manually yii provides access control filter to do this work. for example if your site’s default controller is SiteController then add the accessControl filter in the filters() method and add accessRules() to it and grant permission to access any action for authenticated users except login action