Access controller-attribute in a model?


in my controller-class (which is the parent of any other controller) I defined an attribute.

Is there a way to access this attribute in a model class?



Yii::app()->controller->something should refer to it.

But I don’t think it’s a good idea to see a controller attribute from a model. By doing so, you will make your model dependent of your controller. It should be other way round.

Ok, makes sense…

So what is the best way to define global variables in Yii?

I’m not very sure, but what kind of information do you plan to hold in the global varialbes, and what for?

Question your assumption - do you need globals at all?

If in context of a logged in user you can use Yii’s builtin session management to persist a variable available under Yii::App()->user()->yourVar

I have are certain Parameters that influence the behavoir of my app.

I want to keep these in global variables…

i donÄt need context specific variables…

It should be independent of any user…


How are the variables set if not on login? Are you setting stuff from a database table that an administrator can configure? There are a few good extensions to manage config data in a table and use it throughout your application. The basic idea is that you are using a Config class which can be referenced as needed in various controllers.

If you don’t really need a DB but want to refer to a configuration that is static you can use the Yii main config file.

THX, for some reason I completely forgot about the config/main