C
C
cat_crash2014-06-11 09:25:32
Yii
cat_crash, 2014-06-11 09:25:32

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.

Ps I know about Yii::app()->params['city']

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vit, 2014-06-11
@cat_crash

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 question

Ask a Question

731 491 924 answers to any question