【发布时间】:2013-06-17 09:54:24
【问题描述】:
我真的需要很大的帮助。 我有一个表格,客户可以在该表格中选择国家和文件类型,还有添加到购物车按钮。
因此,当客户端选择他需要的所有内容时,所有参数都会像这样发送到会话中(这是在控制器中):
$quantity = 1; //this is default quantity for all documents
if(isset($_POST['cartBtn'])) {
if(!isset(Yii::app()->session['cart_values'])) {
Yii::app()->session['cart_values'] = array();
}
$sessionCart = Yii::app()->session['cart_values'];
$productInfo = Product::model()->find('id=:id',(array(':id'=>$_POST['documents'])));
$sessionCart[] = array('product_id' => $_POST['documents'], 'document' => $productInfo->name, 'countries'=>$_POST['countries'], 'quantity'=> $quantity, 'price' => $unitCost);
Yii::app()->session['cart_values'] = $sessionCart;
$this->redirect(array($this->id."/cart"));
}
提交表单后,客户被重定向到购物车表单,在此表单中他可以更新文档的数量。 现在我必须确定客户端选择更新哪一列。
我尝试在控制器中执行此操作(在购物车操作下):
public function actionCart()
{
if(isset($_POST['cartBtnUpdate'])) {
$sessionCart['quantity'] = $_POST['quantity'];
}
$this->render('cart');
}
但是当我这样做时,值是 1,我输入 2 或 3 提交表单,但值是 1。
如果有人单击复选框并提交表单,我也想删除该字段,但我不知道如何选择所有会话行来删除它。
谢谢。
购物车视图中的表单代码:
<?php
if (is_array(Yii::app()->session['cart_values']))
{
$total = 0;
foreach ( Yii::app()->session['cart_values'] as $value) {
$total += $value['price'];
?>
<tr id="TDcartTable">
<td class="docName">
<?php echo $value['document'] ?>
</td>
<td>
£ <?php echo number_format($value['price'], 2); ?>
</td>
<td>
<?php echo CHtml::textField('quantity', $value['quantity']); ?>
</td>
<td>
£ <?php echo number_format(($value['price'] * $value['quantity']), 2);
?>
</td>
<?php }
}
?>
<td>
</td>
</tr>
<tr>
<td class="column-last" colspan="6">
</td>
</tr>
<tr>
<td class="cart-order-total" colspan="6">
<?php echo CHtml::encode(Yii::t('app', 'Order Total')); ?>: £ <?php echo number_format($total, 2); ?>
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" class="button" name="cartBtnUpdate" value="<?php echo CHtml::encode(Yii::t('app', 'Update Your Shopping Cart')); ?>">
</td>
<td colspan="4">
<input type="submit" class="button" name="cartBtnContinue" value="<?php echo CHtml::encode(Yii::t('app', 'Continue')); ?>">
</td>
</tr>
【问题讨论】:
-
这是你第三次问这个问题了。很高兴看到你这次包含了更多细节。如果答案不是您需要的,您应该改进问题而不是提出新问题。
-
是的,我很抱歉,我只是没有得到答案,我担心没有人会看到我的问题。我真的不明白这个更新会话的东西,我开始感觉不好。
-
Value with same name in Array 的可能重复项 - 不要重复您自己的问题 - 永远不会 - 而是编辑前一个问题以改进它。跨度>