What Is The Controller Class For Theme In Yii

Hi Everyone,

I want to show the current logged in user’s role name in the top-left of my theme and I have written a method which returns the name of the role of current logged in user. I do not understand in which controller I should place this method which will work in theme. I wrote that method in DefaultController.php but it works only for http://localhost/[my project name]/index.php/admin/default/index. When I trigger to other controller it gives error. Is there any place where I write methods for theme or any controller class for theme.

Thanks in advance

See below pages, and hope them can give you some idea, also search "theme" in wikis.



You have to put this method into components\Controller (parent class for all app controllers). Or maybe a better idea is to make a widget "UserRoleWidget" and call it from any view file.

I have applied the first way, get success. Now trying to make widget. Many thanks for this advice.