session problem

I have this code that cause the error Call to a member function addItem() on a non-object at AddToCart : $this->cart_object->addItem, what is wrong?


Yii::import('application.extensions.faucart.faucart');

class Cart extends CFormModel { 

    private  $cart_name		= "MYFAUCART";

    private $cart_object	= null;

    function __consruct() {

       session_start();

        $this->inSession();

        parent::__consruct();




    }


    //gia arxikopiisi tis cartas

    function inSession() {




        if (isset($_SESSION[$cart_name]))

            $this->cart_object = unserialize($_SESSION[$this->cart_name]);

        else

            $this->cart_object = new faucart();

    }

    //vazi sto session tis allages

    function toSession() {


        


        if (isset($_SESSION[$this->cart_name]))

            unset($_SESSION[$this->cart_name]);

        $_SESSION[$cart_name] = serialize($this->cart_object);

    }

    public function AddToCart($name,$comment,$price) {


        $this->cart_object->addItem(new faucartelement($name,$comment,$price));

        $this->toSession();

    }...

$this->cart_object is null for some reason. :blink:

Try __construct() instead (unless IPBoard swallowed the ‘t’)

/Tommy

Something is wrong with the inSession code, when I call from controller this function with only


$this->cart_object = new faucart();

it works but with the others no.

I did it by there is a problem with the session code as previous post

I thing I solved this error:

[code]if (isset(Yii::app()->session[$this->cart_name]))

     $this->cart_object = Yii::app()->session[$this->cart_name];


    else


     $this->cart_object = new faucart();