/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionAjax($id) { $model = new Doccheques(); $type = PaymentType::findOne($id); if ($type !== null) { //return $this->renderPartial('ajax', array( return $this->render('ajax', array('model' => $model, 'type' => $type)); Yii::$app->end(); } if ($model->load(Yii::$app->request->post())) { if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } return $this->renderPartial('create', array('model' => $model)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionAjax($id) { $model = new Doccheques(); $type = PaymentType::model()->findByPk($id); if ($type !== null) { //$this->renderPartial('ajax', array( $this->render('ajax', array('model' => $model, 'type' => $type)); Yii::app()->end(); } // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Doccheques'])) { $model->attributes = $_POST['Doccheques']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->renderPartial('create', array('model' => $model)); }
private function saveCheq() { if (!is_null($this->docCheq)) { $line = 0; foreach ($this->docCheq as $key => $rcpt) { $submodel = Doccheques::model()->findByPk(array('doc_id' => $this->id, 'line' => $rcpt['line'])); if (!$submodel) { //new line $submodel = new Doccheques(); } //go throw attr if no save new foreach ($rcpt as $key => $value) { if ($submodel->hasAttribute($key)) { $submodel->{$key} = $value; } else { $eav = new DocchequesEav(); $eav->line = $rcpt['line']; $eav->doc_id = $this->id; $eav->attribute = $key; $eav->value = $value['value']; $eav->save(); } } $submodel->doc_id = $this->id; if ((int) $rcpt["type"] != 0) { if ($submodel->save()) { $saved = true; $line++; } else { Yii::log("fatel error cant save rcptdetial,doc_id:" . $submodel->line . "," . $submodel->doc_id, CLogger::LEVEL_ERROR, __METHOD__); //Yii::app()->end(); } } //Yii::app()->end(); } if (count($this->docCheques) != $line) { //if more items in $docCheques delete them for ($curLine = $line; $curLine < count($this->docCheques); $curLine++) { $this->docCheques[$curLine]->delete(); } } } }