당신이 사용할 수있는 PHP의 인터페이스 직렬화 OOP와 더 얻으려고 : http://php.net/manual/de/class.serializable.php
당신은보다 효율적으로 카트의 인스턴스를 변환하는 데 사용할 수 있습니다 가치 (당신이 정의한 것, 정확하게 무엇이 저장되어 있는지). 이것은 당신의 경우 2 차원 배열이다. 이 같은
시도 뭔가 :
<?php
class Cart implements Serializable {
// your normal code for the Cart class
public function serialize() {
$cartData = array();
foreach($this->cartItems as $item) {
$cartData[] = array(
'count' => $item->getCount(),
'productId' => $item->getId()
);
}
return serialize($cartData);
}
public function unserialize($cartData) {
$this->cartItem = array();
foreach($cartData as $item) {
// replace this with the appropriate propel code
$product = loadProductWithPropelById($item['id']);
$this->cartItems[] = new CartItem($item['count'], $product);
}
}
}
?>
그런 다음 세션에서 카트를 저장하는 직렬화를 사용하고 검색 : 당신의 프로젝트에
<?php
// Store cart to session
$_SESSION['cart'] = serialize($cart);
// get cart from session
$cart = unserialize($_SESSION['cart']);
?>
행운을 빕니다!
카트 데이터를 데이터베이스에 저장하는 데는 아무런 문제가 없습니다. http://stackoverflow.com/questions/297576/storing-shopping-cart-in-session을 참조하십시오. – Phil