Пример #1
0
 /**
  * Creates a new Matricula model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Matricula();
     $modeldetallemat = [new Detallemat()];
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $modeldetallemat = Model::createMultiple(Detallemat::classname());
         Model::loadMultiple($modeldetallemat, Yii::$app->request->post());
         // validate all models
         $valid = $model->validate();
         $valid = Model::validateMultiple($modeldetallemat) && $valid;
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $model->save(false)) {
                     foreach ($modeldetallemat as $modeldetallemat) {
                         $modeldetallemat->idMatricula = $model->idMatricula;
                         if (!($flag = $modeldetallemat->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect(['view', 'id' => $model->idMatricula]);
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
         return $this->redirect(['view', 'id' => $model->idMatricula]);
     } else {
         return $this->render('create', ['model' => $model, 'modeldetallemat' => empty($modeldetallemat) ? [new Detallemat()] : $modeldetallemat]);
     }
 }
Пример #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Detallemat::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['iddetalle' => $this->iddetalle, 'nota' => $this->nota, 'idTipoa' => $this->idTipoa, 'idGrupo' => $this->idGrupo, 'idMatricula' => $this->idMatricula]);
     return $dataProvider;
 }
Пример #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getDetallemats()
 {
     return $this->hasMany(Detallemat::className(), ['idMatricula' => 'idMatricula']);
 }
Пример #4
0
 /**
  * Finds the Detallemat model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Detallemat the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Detallemat::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Пример #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getDetallemats()
 {
     return $this->hasMany(Detallemat::className(), ['idGrupo' => 'idGrupo']);
 }