Change layout in Component Controller

I use multi layout di Component Controller with function like this.

But the result not show layout what i means, still use layout main.

my code :

public function beforeAction($action)


        if (Yii::app()->user->isGuest && $action->id != 'login') {

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



Maybe add revision on yii 1.1.16?

what is your function inside the Controller class ?

i’m not sure why you set ‘layout’ and then make the page redirect into another page.

you should set the layout in the ‘user/login’ action.

Yes, i use different layout when user before login and after login. And default controller is siteController.


As Hermans says, why do you set layout and then redirects?

I think you only have to write this code into your login action:



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




     $this->layout = 'another layout';


And on the other actions, you can set another layout and ready (or you can use the default controller layout).