【发布时间】:2016-10-03 13:15:12
【问题描述】:
我在从 '$_SESSION' 数组中删除对象时遇到问题。 我的目标是在选择一个特定产品后从阵列中删除每个产品。这是视图部分:
<?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:
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_r:
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
)
)
)
但是,什么都没有发生...有人可以帮忙吗?
【问题讨论】: