/** * Создает новую модель Шифра. * Если создание прошло успешно - перенаправляет на просмотр. * * @return void */ public function actionCreate() { $model = new Cost(); if (Yii::app()->getRequest()->getPost('Cost') !== null) { $model->setAttributes(Yii::app()->getRequest()->getPost('Cost')); if ($model->save()) { Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('BalanceModule.balance', 'Запись добавлена!')); $this->redirect((array) Yii::app()->getRequest()->getPost('submit-type', ['update', 'id' => $model->id])); } } $this->render('create', ['model' => $model]); }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $cost = new Cost(); $data = Input::all(); // Revisamos si la data es válido if ($cost->isValid($data)) { // Si la data es valida se la asignamos al cost $cost->fill($data); // Guardamos el cost $cost->save(); return Redirect::to('admin/cost')->with('success_message', 'El registro ha sido ingresado correctamente.')->withInput(); } else { // En caso de error regresa a la acción create con los datos y los errores encontrados return Redirect::back()->withInput()->withErrors($cost->errors); } }
public function setCost(CostForm $CostForm) { if (!empty($this->special_technique_id)) { $special_technique_id = $this->special_technique_id; Yii::app()->db->createCommand("DELETE FROM {{special_technique_cost}} WHERE special_technique_id=:special_technique_id")->bindParam(':special_technique_id', $special_technique_id)->execute(); } for ($i = 1; $i <= CostForm::count; ++$i) { if ($CostForm->{"value_{$i}"} == '') { break; } $Cost = new Cost(); $Cost->value = $CostForm->{"value_{$i}"}; $Cost->currency_id = $CostForm->{"currency_id_{$i}"}; $Cost->type_id = $CostForm->{"type_id_{$i}"}; $Cost->cash = $CostForm->{"cash_{$i}"}; $Cost->nds_include = $CostForm->{"nds_include_{$i}"}; $Cost->rent_term = $CostForm->{"rent_term_{$i}"}; $Cost->save(); $special_technique_id = $this->special_technique_id; $cost_id = $Cost->cost_id; Yii::app()->db->createCommand("INSERT INTO {{special_technique_cost}}(special_technique_id, cost_id, `order`) VALUES(:special_technique_id, :cost_id, :order)")->bindParam(':special_technique_id', $special_technique_id)->bindParam(':cost_id', $cost_id)->bindParam(':order', $i)->execute(); } }