Need help with converting this


I am having a hard time converting this to yii.

I know how to change the session syntax, but how do I change this class to a singleton?

Where would I install this class once it is converted?

Sorry, but I am a newbie to yii and this is a bottleneck for me.

Thanks in advance.

If i where you i’d rewrite the cart. You can maybe borrow the basic concept but i’d refactor the interface.

Basic idea:

class MyCart extends CApplicationComponent


    public function init() {  /* initialize the cart, maybe set up session if you don't autostart it */ }

    public function add($article) { /* code to add an article here */ }

    public function total() { /* code to calculate total price of articles here */ }

    // ... 


Setup as application component in you configuration:






Access from everywhere like:

echo Yii::app()->cart->total();

Thanks Mike, that helped me a lot.

SI am still new to yii.