public function actionEdit() { $message = ""; $lang = CatLang::fetchAll(); if (!empty($_POST["trans"])) { for ($n = 0; $n < sizeof($lang); $n++) { $trans = $_POST["trans"][$n]; if ($trans["id"] > 0 || $trans["translation"]) { if ($trans["id"] > 0) { $model = I18nTranslate::fetch($trans->id); } else { $model = new I18nTranslate(); } $model->setAttributesFromArray($trans); $model->i18n_id = $this->id; if (!$model->save()) { print_r($model->getErrors()); } } } } $list = array(); if (!empty($this->id)) { $item = I18n::fetch($this->id); $list = I18nTranslate::fetchAll(DBQueryParamsClass::CreateParams()->setConditions("i18n_id=:id")->setParams(array(":id" => $item->id))->setLimit(-1)->setCache(0)); } else { $item = new I18n(); } $this->render('edit', array('form' => $item, 'list' => $list, 'lang' => $lang, 'message' => $message)); }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate() { if (!empty($_POST["I18n"])) { if ($this->id > 0) { $model = I18n::fetch($this->id); $modelTranslate = I18nTranslate::fetch($this->id); } else { $model = new I18n(); $modelTranslate = new I18nTranslate(); } $message = ""; // Сохрание полей $model->setAttributesFromArray($_POST["I18n"]); if ($model->save()) { $modelTranslate->id = $model->id; $modelTranslate->translation = $model->message; $modelTranslate->language = Yii::app()->language; if (!$modelTranslate->save()) { print_r($modelTranslate->getErrors()); } $message = "Данные успешно сохраненны"; } $this->render('edit', array('form' => $model, 'translate' => $modelTranslate)); } else { $this->redirect(SiteHelper::createUrl("/console/variable")); } }