mithereal
(Mithereal)
April 29, 2010, 12:45am
1
is therre a way i can make application wide globals ie accessable via Yii::app()->variable?
basically i have a $state variable i need to access anywhere in the application thtas tied to the uers so maybe Yii:app()->user->state. but the state comes from an unrelated model, do i have to load in this model everytime i make a request, or can i stick the static variables in a static class.
jerry2801
(Jerry2801)
April 29, 2010, 2:00am
2
Yii::app()->params[‘xyz’]
?
mdomba
(Maurizio Domba Cerin)
April 29, 2010, 8:12am
3
JamesBarnsley
(Jamesbarnsleyfreelance)
December 12, 2010, 11:12pm
4
Is it possible to store an object in set state, or do only variables work?
mdomba
(Maurizio Domba Cerin)
December 13, 2010, 7:15am
5
setState() stores values in session ($_SESSION)…
it is possible to store even objects but it’s not a good practice… it’s better to store only some ID for example (PK)… and then recreate the object…
zaccaria
(Matteo Falsitta)
December 13, 2010, 7:23am
6
You can try, if it works is ok. If you have problem, you can use serialize and unserialize for repair.
arielon
(Ari)
March 10, 2012, 6:09am
7
http://www.yiiframework.com/wiki/242/yii-registry-how-to-use-it-does-it-exist-at-all/
set variable:
Yii::app()->params[‘abc’] = 123;
get variable:
echo Yii::app()->params[‘abc’];
Although my taste is to have them in the main.php config file for each application.
Yii::app()->params[‘abc’]= 123
echo Yii::app()->params[‘abc’];
This is Handy !
Hi,
If you want to add number of variable you can extend the class CApplicationComponent
[b]
[/b]
and do your stuffs as your wish.
below an example
class vars extends CApplicationComponent {
public $your_variable = 'Your Value';
// and so ON...
//Also your functions
}
So you can access the variable $var1 as follows
echo Yii::app->vars->your_variable;
It gives the output : Your Value
[b]
[/b]I tested its working fine even you can set and get values for that variable.
If you like Don’t forget to press +1
[b]
[/b]
Cheers !