Where and how do i set default login URL?

How do i set default login url?

I tried to modify CWebUser

public $loginUrl=array('site/login');


public $loginUrl=array('accounts/login');

But seems it didn’t work

Thanks beforehand.

Do it in your main config:

// application components






Thanks a lot, it works.


what if I want to set 2 different login URL, one for public user, and one for admin.

can we do it this way?

Thank you Very much , It solved my problem Also ,

One Another Problem.

If any user have no access to a specified Action , it redirects to some another File .

Can you please show me the method to change no access url.

Thanks anyway

In config write

'behaviors' => array('ApplicationConfigBehavior'),

In protected/components/ApplicationConfigBehavior.php write

class ApplicationConfigBehavior extends CBehavior


    public function events()


        return array_merge(parent::events(),array(




    public function beginRequest()


	$uri = explode('/', $_SERVER['REQUEST_URI']);

        if ($uri[1] == 'admin')

            Yii::app()->user->loginUrl = '/admin/login';



Exploding the REQUEST_URI to fetch the "location" of the controller from the array is a rough hack…

Do it properly, Yii gives us everything we need.

$controller = Yii::app()->controller->id

$action = Yii::app()->controller->action->id

I have them as variables to show how you can grab both the controller and action in use.

You need to create a custom behavior, grab the controller, and do whatever you need with the controller name.

Try this link: larryullman.com/2010/07/20/forcing-login-for-all-pages-in-yii/ (Sorry, I can’t post links but i think its helpful)

You need to customize what he is doing, by using your own code in the handleBeginRequest() function. For example, I used it to override the loginUrl to use different login URL’s depending on what controller they are using.

Good luck.

thanks, helpful for me