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

这是我的代码,我遗漏了一些明显的东西,但无法弄清楚:


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,日志中也没有任何内容。


慕盖茨4494581
浏览 184回答 1
1回答

RISEBY

尝试var_dump($userProfile->getErrors())保存后立即查看是否有与模型字段相关的错误。
打开App,查看更多内容
随时随地看视频慕课网APP