Create an "admin" theme

Hi,

is it possible to create admin theme for my web app? It means when I’m browsing through a site as a guest i see the default theme, but when i’m logged in i see admin theme with permissions to do all CRUD commands…

is a best practice how do this???

thank you.





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

  Yii::app()->themeManager->theme = 'guesttheme';

} else if(!Yii::app()->user->isGuest) {

  Yii::app()->themeManager->theme = 'admintheme';

}




Read more about this in the ‘themes’ section of the definitive Guide to Yii.

If your Application get’s more Complex than only guest and admin, you should think about using

the Role-Based Access System, and, i highly suggest the SRBAC Extension for this.

Where did you put this code? in a model, controller?

It’s possible that you have some examples of this? I need the same.

I was install the srbac and this works awesome. now, I need that guest, registered and admin use different theming, but I do not how can I make. Thanks in advanced.

Regards,

i tried it, it gave me error read only property. i also tried to use setTheme function but it seems applicable only to that controller and that is too only one time?

I suggest you add this in protected/components/Controller.php:




	public function init()

	{

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

			Yii::app()->theme = 'guest';

		} else {

			Yii::app()->theme = 'identified';

		}

		parent::init();

	}



This way all the controllers will apply your theme change.

If it still doesn’t load your theme files, it might come from your scaffolded code, have a look at this other post.

Hi François Gannaz,

I’am struggling wid a similar problem. your above code to put in controller.php works perfectly fine. but if i want to change the themes based on either the controllers or the actions in the controller?