/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { if (isset($_POST['Production'])) { $err = 0; foreach ($_POST['Production'] as $postrans) { $model = new Production(); //id_trans, qty, date_time, decsription, balance_history, component_id, user_id $model->goods_id = $postrans['goods_id']; $model->components_qty = $postrans['components_qty']; $model->decsription = $postrans['decsription']; $model->warehouse_id = $postrans['warehouse_id']; $messageError = ""; if (!$model->save()) { $errors = $model->getErrors(); foreach ($errors as $e) { $messageError .= ' <p id="error" class="info"> <span class="info_inner">' . $e[0] . '</span> </p>'; } Yii::app()->user->setFlash('error', $messageError); $err++; } } if ($err == 0) { Yii::app()->user->setFlash('success', '<p id="success" class="info"> <span class="info_inner">Your transaction has been save successfully</span> </p>'); } //echo "kookokokok"; $this->redirect(array('create')); } $this->render('index'); }
/** * Stores the object in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param Connection $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave($con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aUser !== null) { if ($this->aUser->isModified()) { $affectedRows += $this->aUser->save($con); } $this->setUser($this->aUser); } if ($this->aProduction !== null) { if ($this->aProduction->isModified()) { $affectedRows += $this->aProduction->save($con); } $this->setProduction($this->aProduction); } // If this object has been modified, then save it to the database. if ($this->isModified()) { if ($this->isNew()) { $pk = ProductionHistoryPeer::doInsert($this, $con); $affectedRows += 1; // we are assuming that there is only 1 row per doInsert() which // should always be true here (even though technically // BasePeer::doInsert() can insert multiple rows). $this->setProductionHistoryId($pk); //[IMV] update autoincrement primary key $this->setNew(false); } else { $affectedRows += ProductionHistoryPeer::doUpdate($this, $con); } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } $this->alreadyInSave = false; } return $affectedRows; }
/** * Save or update a production object * * @param Production $production : A production object */ public function createProduction($production) { try { return $production->save(); } catch (Exception $e) { echo $e; return null; } }