/**
  * Creates a new Prerrequisito model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Prerrequisito();
     $modelsDetallepre = [new Detallepre()];
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $modelsDetallepre = Model::createMultiple(Detallepre::classname());
         Model::loadMultiple($modelsDetallepre, Yii::$app->request->post());
         // validate all models
         $valid = $model->validate();
         $valid = Model::validateMultiple($modelsDetallepre) && $valid;
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $model->save(false)) {
                     foreach ($modelsDetallepre as $modelsDetallepre) {
                         $modelsDetallepre->idPrerreq = $model->idPrerreq;
                         if (!($flag = $modelsDetallepre->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect(['view', 'id' => $model->idPrerreq]);
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
         return $this->redirect(['view', 'id' => $model->idPrerreq]);
     } else {
         return $this->render('create', ['model' => $model, 'modelsDetallepre' => empty($modelsDetallepre) ? [new Detallepre()] : $modelsDetallepre]);
     }
 }
Example #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Detallepre::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(['iddetpre' => $this->iddetpre, 'idPrerreq' => $this->idPrerreq, 'idAsignatura' => $this->idAsignatura]);
     return $dataProvider;
 }
Example #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getDetallepres()
 {
     return $this->hasMany(Detallepre::className(), ['idPrerreq' => 'idPrerreq']);
 }
 /**
  * Finds the Detallepre model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Detallepre the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Detallepre::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getDetallepres()
 {
     return $this->hasMany(Detallepre::className(), ['idAsignatura' => 'idAsignatura']);
 }