Yii Global variable

How can I set a global variable accessible everywhere and init in the home index.php ( not the view ) ?

Anyway another question. If I require some php file in the index.php ( the same of abobe ), these required php file will be in every other pages? I mean, index.php loads every other file right? So if I use in this index.php some variable I can access them in other files?

When you say global is for request, session or for the entire app??

If it’s for your request, add it in the app config (with a function at application parameters).

if it’s for session add it in the user, and if it’s for the entire app, add it to the global state :D

user never log in (i’m developing facebook app so i use facebook login ).

So i have to put this var global for the entire app :)

And to include php pages every where in the app?

Could you share your facebook authentication code as an extension maybe?

fb auth is done with the facebook object.

$fb -> require_login() :)

Anyway I started developing yesterday :) So I’m always in the first step of the project ;)

any progress here? ;)

From sebas Post




 if it's for the entire app, add it to the global state 



This is what I need to do at the application level. So, where is the "global" state and how do I modify it?

What I need is to be able to get a list of records and have them available to the entire application at all times. It’s a small list but the point is that it is not a single value. In other languages I’ve gotten this once and stored it in the cache. When it gets removed from the cache, I retrieve the values again and store it in the cahce. What would be the best way to go about this with yii.

Are there any examples of working with the cache you can point me to?

I know I’m replying to a 2 years old post, but it maybe helpful to someone:

Setting a variable which is available throughout the application:

In your main index.php:

$app = Yii::createWebApplication($config);

$app->setGlobalState(‘site_id’, SITE_ID);

$app->run();

You can then access this variable using:

Yii::app()->getGlobalState(‘site_id’); // Available throughout the site.