Revision #3 has been created by zaccaria on Jun 2, 2011, 6:31:38 AM with the memo:
it is not singleton
« previous (#2)
Singleton in Yii
Singleton is a desing pattern that is very useful when exactly one object is needed to coordinate acti
cross the system.
In Yii there are many implementation of this pattern, for example Yii::app()->db.
In this article we will learn how to create a singleton.
### Creating the class
[...]Let's imagine we need almost everywhere an instance of the class Region, and we want to avoid to do too much queries.
We can create a class which extends CApplicationCompo
ment, like that:
This approach can be very useful and resource-saving, b
ut is better to avoid to as it introduces global state into an application, and that can lead to bad practices