为了账号安全,请及时绑定邮箱和手机立即绑定

Yii2 - 即使条件满足,数据也不会保存在数据库中,日志中也没有任何内容

Yii2 - 即使条件满足,数据也不会保存在数据库中,日志中也没有任何内容

PHP
慕盖茨4494581 2022-07-09 18:20:49
这是我的代码,我遗漏了一些明显的东西,但无法弄清楚:public function actionCheckout()    {               $model = new User;     //  $userProfile = UserProfile::find(['user_id'=>$model->id])->One();       $userProfile = new UserProfile;       $cartItems = $this->cart->getItems();        if (Yii::$app->request->post())  {            $cart = (array_merge(...$_SESSION['primary-cart']));                     if($_POST['account-option']=="on"){             //   echo "true";exit;                $userProfile->first_name = $_POST['User']['first_name'];                $userProfile->last_name = $_POST['User']['last_name'];                $userProfile->phone = $_POST['User']['phone'];                $userProfile->email = $_POST['User']['email'];                $userProfile->address1 = $_POST['UserProfile']['address1'];              //  $userProfile->address2 = $_POST['UserProfile']['address2'];                $userProfile->city = $_POST['UserProfile']['city'];                $userProfile->state = $_POST['UserProfile']['state'];                $userProfile->Country = $_POST['User']['Country'];                $userProfile->pincode = $_POST['UserProfile']['pincode'];                $userProfile->save();            }            $params=[                'id'=>$cart['productId'],                               'amount'=> $cart['price'],                'productinfo' => $cart['title'],                                'firstname' => $_POST['User']['first_name'],                'email' => $_POST['User']['email'],                'phone' => $_POST['User']['phone']            ];            Yii::$app->Payu->PayuCheckout($params);        }        return $this->render('checkout',['model'=>$model,'userProfile' =>$userProfile,'cartItems' => $cartItems]);    }我被正确地重定向到 payU,没有任何问题,但是数据没有保存到 userProfile,日志中也没有任何内容。
查看完整描述

1 回答

?
RISEBY

TA贡献1856条经验 获得超5个赞

尝试

var_dump($userProfile->getErrors())

保存后立即查看是否有与模型字段相关的错误。


查看完整回答
反对 回复 2022-07-09
  • 1 回答
  • 0 关注
  • 183 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号