다음과 같은 문제가 있습니다. 클래스가 있습니다 CartItem입니다. 나는 CartItem의 객체들의 배열을 세션에 저장하려고한다. (사실 나는 장바구니를 구현하고있다.) 내가 잘못이 라인을 쓰고 있어요 생각CakePHP 직렬화 객체
function addToCart(){
$this->loadModel("Cart");
$this->layout = false;
$this->render(false);
$cart = array();
$tempcart = unserialize($this->Session->read("cart"));
if(isset($tempcart)){
$cart = $tempcart;
}
$productId = $this->request->data("id");
if(!$this->existsInCart($cart, $productId)){
$cartItem = new Cart();
$cartItem->productId = $productId;
$cartItem->createdAt = date();
$cart[] = $cartItem;
$this->Session->write("cart", serialize($cart));
echo "added";
}
else
echo "duplicate";
}
:
$tempcart = unserialize($this->Session->read("cart"));
$this->Session->write("cart", serialize($cart));
것은 내가 세션에서 데이터를받지 못했습니다으로
class CartItem extends AppModel{
var $name = "CartItem";
var $useTable = false;
}
나는이 시도.
적절한 카트 구현을 위해 https://github.com/burzum/cakephp-cart-plugin을보십시오 – burzum