如何修复通知(8):未定义的变量:百分比[APP / Template / Cart / checkout.ctp,第182行]
控制器:
if ($this->request->is('post')) {
$CheckCoupon = $this->Campaign->find('all')
->where(['Campaign.discount_coupon_id' => $this->request->data('coupon')])->first();
$percentage = $CheckCoupon['discount_percentage'];
的Ct p:
<?php
$actualTotalAmount=$subtotal;
$discountPercent=$percentage;
$discountAmount=($actualTotalAmount)*($discountPercent/100 );
$requestAmount=$discTotalamount=($actualTotalAmount)-$discountAmount;
?>
答案 0 :(得分:2)
您的Controller代码并未显示您实际将$percentage
变量传递给视图。要将变量传递给CakePHP中的视图,您需要使用set
: -
$this->set('percentage', $percentage);
当变量名与您要设置的变量名相同时,您还可以使用PHP's compact
method创建一个包含变量及其值的数组: -
$this->set(compact('percentage'));