So I am thinging to create a controller for the actions addtocard,removefromcard,mycard etc
As the instructions say this cart must be at session, so I want to ask if this code at controller will be ok.
I use codeigniter with this card and I made a model to connect with it but as I understand Yii models are not the same exactly.
Yii::import('application.vendors.*');
require_once('wfcart/wfCart.php');
class CardController extends CController
{
private $session;
private $cart;
function __construct()
{
if (!$this->session->isInitialized)
{
$this->session=new CHttpSession;
$session->open();
}
$$this->cart =$this->session['wfcart']; // point $cart to session cart.
if(!is_object( $this->cart))$this->cart = new wfCart(); // if $cart ( $_SESSION['cart'] ) isn't an object, make a new cart
}
// function addtocart etc
}
Yii::import('application.vendors.*');
require_once('wfcart/wfCart.php');
class CardController extends CController
{
private $session;
private $mcart;
function __construct()
{ parent::__construct('card');
if (!is_object($this->session))
{
$this->session=new CHttpSession;
$this->session->open();
}
$this->mcart =$this->session['wfcart']; // point $cart to session cart.
if(!is_object( $this->mcart))$this->mcart = new wfCart(); // if $cart ( $_SESSION['cart'] ) isn't an object, make a new cart
}
public function actionIndex()
{
$this->mcart->add_item(25,1,25,'test');
$this->render('index',array('cart'=>$this->mcart));
}
but when I run this action,card is empty even if I run index action of card,what is wrong?
public function actionMake()
{ print_r($this->mcart);
// $this->mcart->add_item(25,1,25,'test');
// $this->render('index',array('cart'=>$this->mcart));
}