/**
  * Updates an existing Veiculo model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post())) {
         $model->datacompra = implode("-", array_reverse(explode("/", $_POST['Veiculo']['datacompra'])));
         if ($model->save()) {
             if ($_POST['Veiculo']['atributoveiculo']) {
                 foreach ($_POST['Veiculo']['atributoveiculo'] as $key => $value) {
                     $atributo = new Atributoveiculo();
                     $atributo->descricaoatributo = $value;
                     $atributo->idveiculo = $model->idveiculo;
                     $atributo->save();
                 }
                 if ($atributo->idatributoveiculo) {
                     return $this->redirect(['view', 'id' => $model->idveiculo]);
                 } else {
                     return $this->render('update', ['model' => $model]);
                 }
             } else {
                 return $this->redirect(['view', 'id' => $model->idveiculo]);
             }
         }
     } else {
         return $this->render('update', ['model' => $model]);
     }
 }
 public function actionDelete($id)
 {
     Atributoveiculo::deleteAll(['idveiculo' => $id]);
 }
Example #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getatributoveiculo()
 {
     return $this->hasMany(Atributoveiculo::className(), ['idveiculo' => 'idveiculo']);
 }