how do I create a singleton class in yii

Hello,

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

Thanks

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

http://www.yiiframework.com/doc/guide/basics.application#application-component

http://www.yiiframework.com/doc/guide/basics.component

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.

CApplicationComponent