public function actionProfile() { // if(\Yii::$app->user->isGuest) // return $this->redirect( Yii::$app->urlManager->createUrl('site/login')); $userdetails = \Yii::$app->user->identity; $model = UserProfile::find()->where(['user_id' => $userdetails->id])->one(); if (empty($model)) { $model = new UserProfile(); } $address = Address::find()->where(['user_id' => $userdetails->id])->one(); if (empty($address)) { $address = new Address(); } $userpay = UserPay::find()->where(['user_profile_id' => $userdetails->id])->one(); if (empty($userpay)) { $userpay = new UserPay(); } $user = Userform::findOne(['id' => $userdetails->id]); if (!empty($model->image)) { $oldpic = $model->image; } else { $oldpic = ''; } // if (isset($_POST['User'])) { // $user->fname = $_POST['User']['fname']; // $user->lname = $_POST['User']['lname']; // if ($user->validate(array('fname', 'lname'))) { // $user->update(); // } // } if (isset($_POST['UserProfile'])) { // if (empty($_POST['UserProfile']['state_id'])) { // // $model->addError('state_id', 'Please select a state', array('class' => 'errorMsg')); // return $this->render('profile', ['model' => $model, 'user' => $user]); //// $model->validate(); //// echo "<pre>";print_r('hello');die; // Yii::$app->end(); // } $model->attributes = $_POST['UserProfile']; if (isset($model) && $model->user_id) { $model->modified = new \yii\db\Expression('NOW()'); } else { $model->created = new \yii\db\Expression('NOW()'); } $model->user_id = Yii::$app->user->identity->id; $model->description = $_POST['UserProfile']['description']; $model->gender = $_POST['UserProfile']['gender']; //$model->phone=$_POST['UserProfile']['phone']; //$model->address=$_POST['UserProfile']['address']; //$model->city_id=$_POST['UserProfile']['city_id']; //$model->country_id=$_POST['UserProfile']['country_id']; //$model->zip=$_POST['UserProfile']['zip']; //$model->state_id=$_POST['UserProfile']['state_id']; $model->image = $oldpic; // if (!empty($_POST['userimage'])) { // $folder = 'userimages/'; // $myArray = explode('_', $_POST['userimage'], 2); // $tmpfolder = yii::$app->basePath . DIRECTORY_SEPARATOR . "web" . DIRECTORY_SEPARATOR . "imgtemp" . DIRECTORY_SEPARATOR; // $name = Yii::$app->basePath . "/web/imgtemp/" . $_POST['userimage']; // if (file_exists($name)) { // $filename = $folder . $myArray[1]; // // list($width, $height) = getimagesize($name); // $image = Yii::app()->iwi->load($name); // if($width >= 160 && $height >= 160){ // $image->resize(160, 160, Iwi::NONE);} // $image->save(); // $ar = explode('.', $filename); // $newname = $ar[0].'_160x160.'.$ar[1]; // $dest = $tmpfolder . time() . '_usrimg' . $myArray[1]; // copy($name, $dest); // SiteUtil::UploadS3($newname, $dest); // SiteUtil::UploadS3($filename, $dest); // // $image = Yii::app()->iwi->load($name); // if($width >= 70 && $height >= 70){ // $image->resize(70, 70, Iwi::NONE);} // $image->save(); // $ar = explode('.', $filename); // $newname = $ar[0].'_70x70.'.$ar[1]; // $dest1 = $tmpfolder . time() . '_usrimgthumb' . $myArray[1]; // copy($name, $dest1); // SiteUtil::UploadS3($newname, $dest1); // // $image = Yii::app()->iwi->load($name); // if($width >= 50 && $height >= 50){ // $image->resize(50, 50, Iwi::NONE);} // $image->save(); // $ar = explode('.', $filename); // $newname = $ar[0].'_50x50.'.$ar[1]; // $dest2 = $tmpfolder . time() . '_usrimg1' . $myArray[1]; // copy($name, $dest2); // SiteUtil::UploadS3($newname, $dest2); // // $image = Yii::app()->iwi->load($name); // if($width >= 35 && $height >= 35){ // $image->resize(35, 35, Iwi::NONE);} // $image->save(); // $ar = explode('.', $filename); // $newname = $ar[0].'_35x35.'.$ar[1]; // $dest3 = $tmpfolder . time() . '_usrimg2' . $myArray[1]; // copy($name, $dest3); // SiteUtil::UploadS3($newname, $dest3); // // unlink($name); // unlink($dest); // unlink($dest1); // unlink($dest2); // unlink($dest3); // // $model->image = $filename; // } // } if ($model->validate() && $user->validate()) { $transaction = \Yii::$app->db->beginTransaction(); try { if ($model->save()) { $address->user_id = $model->id; $address->address = $_POST['Address']['address']; $address->landmark = $_POST['Address']['landmark']; $address->pincode = $_POST['Address']['pincode']; $address->country_id = $_POST['Address']['country_id']; $address->state_id = $_POST['Address']['state_id']; $address->city_id = $_POST['Address']['city_id']; $userpay->user_profile_id = $model->id; $userpay->currency_id = 1; $userpay->time_slot_id = 5; $userpay->amount = $_POST['UserPay']['amount']; if ($address->validate() && $userpay->validate()) { $address->save(); $userpay->save(); } } $transaction->commit(); } catch (Exception $e) { $transaction->rollback(); } } } return $this->render('profile', ['model' => $model, 'user' => $user, 'address' => $address, 'userpay' => $userpay]); }