Posted 30 July 2009 - 04:29 AM
You could make a base controller that all controllers extend from and declare any arrays, objects or functions in there you may need throughout the application.
Posted 30 July 2009 - 04:36 AM
Posted 30 July 2009 - 08:40 AM
Currently i just do
Yii::app()->setParams(array('key' => 'value'));
then i just access it using Yii::app()->getParams()->key;
Check out this extension
Posted 30 July 2009 - 11:15 AM
You could just slightly modify it to not use the db - if you don't need to persist your values
Looking at the code I think it shouldn't be a big deal
Just write to an array instead to the database
You could also extract CakePHP's Configure class from cakePHP and use that. Really shouldn't be very hard to do.
Posted 30 July 2009 - 02:25 PM
Almost always, a piece of "global" data has a natural object that it can live with. For example, a web-site visitor/user, whose data you may persist in a session variable -- as an object, of course -- between requests. Or a shopping cart, say, although this is just part of the user object.
The classic case that I've seen numerous times, is where a web-site supports multiple countries/languages and the code is riddled with if-country1-do_this-else-if-country2... creating a shotgun surgery exercise every for every change and making the whole thing unscaleable. That's what polymorphism is for!
I'm kind of intrigued that I see folk asking for something that I regard as odd, and something I don't see elsewhere in an oo environment.
I'm would like to better understand. I'm not judging.
Posted 31 July 2009 - 02:31 AM
I think he understood you just fine, he's just wondering why you need the registry pattern, as in essence, it's just a nicer looking way of adding objects to the global scope
Posted 31 July 2009 - 05:05 PM
Thanks, Vince. That explains a few things.
What I see in the "registry pattern" that you kindly linked to is a singleton that simply provides a global associative array (i.e. a map). Yii already provides the equivalent where it's appropriate -- that is, not to break MVC -- so I'm going to persevere and ask you for more specific details about why you feel that you can't do what you want to Yii. What is it that you can't get from one location to another without the need for a global variable? And what are those locations?