php - Yii 1.1: cross-controller variables (and even cross-view ones) -


For every request, at least I create an example of MyUser , which is the username, Some internal permissions include information, links to avatars and so on.

The thing is that I need this information for each controller, and for most views (to render some controls or not depending on the user status and permissions).

It looks like the need for a global variable, which is requested on time. What is the best way to solve this problem?

Override sebbucer (which you call when you release Yii :: app () -> user) with its custom class web page (placed in components or other folders that contain its classes), and some are found, such as with getRole () example:

  & lt ;? Php class WebUser extends CWebUser {Private $ _model = null; Function getRole () {if ($ user = $ this-> getModel ()) {Return $ user- & gt; UserRole-> Name; }} Private event getModel () {If (! $ $- hg, ugh & $ this-> _model === faucet) {$ this-> _model = User :: model () - & gt; FindByPk ($ this-> ID); } $ $ -> Modell; }}  

If you want the user to have a custom class instead of CWebUser, you must clearly tell what type of application to use in the config:

< Pre> 'user' = & gt; Array ('class' => gt; 'web browser', // ...),

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -