0
'$ _SESSION' 배열에서 객체를 제거하는 데 문제가 있습니다. 내 목표는 특정 제품을 선택한 후 배열에서 각 제품을 삭제하는 것입니다. 이 뷰의 일부입니다
public function deleteProductAction() {
$productID = $this->_getParam('id', 0);
session_start();
$obj = $_SESSION['products'];
foreach ($obj as $key => $product) {
if ($product['product_id'] == $productID) {
unset($product);
}
}
$_SESSION['products'] = $obj;
}
$ OBJ를 printing_r 후 :
<?php
for ($i=0; $i < count($this->products); $i++) {
echo "<a class='remove_from_basket' href='" .$this->baseUrl. "/shop/delete-product/id/" .$this->products[$i]->product_id. "'>Delete</a>";
}
?>
그런 다음 PHP 부분에 내가 함께이 제품 ID를 얻을 수
Array
(
[2] => Zend_Db_Table_Row Object
(
[_data:protected] => Array
(
[product_id] => 26
)
[_cleanData:protected] => Array
(
[product_id] => 26
[_modifiedFields:protected] => Array
(
)
[_table:protected] =>
[_connected:protected] =>
[_readOnly:protected] =>
[_tableClass:protected] => Application_Model_DbTable_Products
[_primary:protected] => Array
(
[1] => product_id
)
)
[3] => Zend_Db_Table_Row Object
(
[_data:protected] => Array
(
[product_id] => 26
)
[_cleanData:protected] => Array
(
[product_id] => 26
)
[_modifiedFields:protected] => Array
(
)
[_table:protected] =>
[_connected:protected] =>
[_readOnly:protected] =>
[_tableClass:protected] => Application_Model_DbTable_Products
[_primary:protected] => Array
(
[1] => product_id
)
)
)
그러나, 아무 일도 일어나지 않습니다 ... 아무도 도와 줄 수 있습니까?
이 부분을 표시 할 때보기 부분에 표시 할 때주의 할 점 : 정의되지 않은 오프셋 : 0 – Peter
@Peter 얻을 수있는 방법이 없습니다. 어떤 코드 블록이이를 생성 했습니까? –
첫 번째 for 루프. – Peter