how do I create a singleton class in yii


How do I create a single instance of a class or extension in yii?


As a component if the class is a child of CComponent.

In case of a foreign class: I am not aware of a way that Yii handles single instances for you.

Thank you.

I want to covert a session shopping cart to yii, and did not know what class I should use.

If my cart is going to be session based, in PHP, I would declare it as static.

So would I just need to extend CComponent?

You can extend it from CApplicationComponent and then access it via Yii::app()->cart.