Set theme...

Action for set theme does not work. Why?

public function actionTheme()





Your theme setting is not persistent. That is when you redirect to another action, the theme setting is lost. You need to save your theme decision using either session or database and recover it for every request.

The setTheme function there only works for this request.

You should chenge it every time you make a request.

Maybe in your controller init function.

Save it to the user session and then change it everytime.

I hope that you specify the best place for code to apply the theme.

Controller poorly suited for this.

Logically, that is framework own store properties in the current sesion.

You could do it in the init() method of your base controller class.


What if you made a component to do it and then define it to preload in your config?  I found in CakePHP I always had way to much code in my controller initialization method, so it seems like a good alternative to me.


What if you made a component to do it and then define it to preload in your config?

Excellent. Thank you.

That's a good idea. Perhaps you can just extend CThememManager so that the code is more relevant to what it does.

BTW, a good idea: you can just extend CWebApplication for save/restore theme and lang (in session) as required application attribute, imho. If session not have stored values Application set default theme and lang or autorecognize lang if possibe. This will be as standard. Is not it?

Yes, you can do that too.

We do not plan to build this into Yii because theme setting may vary project from project. For example, one project may set its theme depending on the current user's profile, while another project is using static theme configuration.

I agree with qiang; it's kind of specific to your scenario