public function actionProviderEdit($id) { $model = new ServiceUser(); $detail = ServiceUser::model()->with('additionalServicePrices')->findByPk(array('id' => $id)); // echo "<pre>";print_r($detail);die; $additionalService = AdditionalServices::model()->findAll(); //echo "<pre>";print_r($additionalService);die; /*foreach($detail->priceAdmins as $i=>$d) { echo "<pre>";print_r($d); } die;*/ if (isset($_POST['ServiceUser'])) { //echo "<pre>";print_r($_REQUEST);die; $model->attributes = $_POST['ServiceUser']; $rnd = rand(0, 9999); $uploadedFile = CUploadedFile::getInstance($model, 'company_logo'); $fileName = "{$rnd}-{$uploadedFile}"; // random number + file name //echo "<pre>";print_r($_FILES);die; if ($model->validate()) { $rec = ServiceUser::model()->with('additionalServicePrices')->findByPk(array('id' => $id)); //echo "<pre>";print_r($_REQUEST);die; $cname = $_REQUEST['ServiceUser']['company_name']; $city = $_REQUEST['ServiceUser']['city']; $zip = $_REQUEST['ServiceUser']['zipcode']; $rec->company_name = $cname; $rec->city = $city; $rec->zipcode = $zip; if (is_uploaded_file($_FILES['ServiceUser']['tmp_name']['company_logo'])) { $rec->company_logo = $fileName; } /*code to save the details for price in db starts here*/ foreach ($rec->priceAdmins as $editPrice) { //echo "<pre>";print_r($editPrice); $editPrice->bedroom = $_REQUEST['PriceAdmin'][$editPrice->service_type_id][0]; $editPrice->bathroom = $_REQUEST['PriceAdmin'][$editPrice->service_type_id][1]; if (!empty($_REQUEST['PriceAdmin'][$editPrice->service_type_id][2]) || !empty($_REQUEST['PriceAdmin'][$editPrice->service_type_id][3])) { $editPrice->property = $_REQUEST['PriceAdmin'][$editPrice->service_type_id][2]; $editPrice->desk = $_REQUEST['PriceAdmin'][$editPrice->service_type_id][3]; } $editPrice->save(); } //die; if (empty($rec->additionalServicePrices)) { foreach ($additionalService as $i => $price) { $mod = new AdditionalServicePrice(); $date = date('Y-m-d'); $mod->date = $date; $mod->additional_service_id = $price->id; $mod->price = $_REQUEST['PriceAditional'][$price->service_name]; $mod->service_id = $id; $mod->save(false); } } //die; foreach ($rec->additionalServicePrices as $editPrice) { //echo "<pre>";print_r($editPrice); $serName = $editPrice->additionalService['service_name']; $editPrice->price = $_REQUEST['PriceAditional'][$serName]; $editPrice->save(); } //die; /*code to save the details for price in db ends here*/ if ($rec->save()) { if (is_uploaded_file($_FILES['ServiceUser']['tmp_name']['company_logo'])) { $uploadedFile->saveAs(Yii::app()->basePath . '/../CompanyLogo/' . $fileName); } $this->redirect(array('providerdetails')); } } else { $errors = $model->getErrors(); //var_dump($errors); } } $this->render('provideredit', array('companyDetail' => $detail, 'model' => $model, 'additionalService' => $additionalService)); }