[solved] config main.php 'defaultController' => 'login' not working

I want all visitors to go to the login page initially.

I’ve made the following changes

In config/main.php

‘defaultController’ => ‘login’

Also In sitecontroller.php

I’ve removed index,view from all users i.e. * so i’m assuming all non-authenticated users will not be allowed these views.

But when i go to webpage it goes to index.php and its visible to un-auth users also.

what am i missing here

make an onBeginRequest event that points to some method




//action that will be executed before any other action

	'onBeginRequest' => array('Bootstrap', 'beginRequest'),

	// application components

	'components'=>array(),



and the method will be something like this




class Bootstrap{

  public function beginRequest(){

//check if the user is logged in

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

//if not run the login controller and and end the application

    	Yii::app()->runController('login');

    	Yii::app()->end();

	}

  }

}



Thanks I just added this to login and index views and redirect to login page if user is Guest.

For rest of the views it works automatically


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