Answer the question
In order to leave comments, you need to log in
Yii: set application level variable
Good day.
In Yii, you can define variables in the config, for example
'language'=>'ru'
and then work with them through Yii::app()->language
Is it possible to somehow define your own variable, for example city, so that you can then reach out to it via Yii::app()->city ?
Now if you define it like that, then the application crashes with an error
Property "CWebApplication.city" is not defined.
Answer the question
In order to leave comments, you need to log in
You can inherit from CWebApplication, declare the fields you need there and use your own class as a web application class. In index.php you call Yii::createWebApplication($config). Instead, you can write Yii::createWebApplication($class, $config) where $class is the name/alias of your application class.
Then Yii::app() will always return an instance of your class to which you added the fields.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question