/** * Updates an existing Articles 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); $model->id_teacher = ArrayHelper::getColumn($model->teachers, 'id'); if ($model->load(Yii::$app->request->post()) && $model->save()) { $model->unlinkAll('teachers', true); $teachers = Teachers::find()->where(['id' => $model->id_teacher])->all(); foreach ($teachers as $teacher) { $model->link('teachers', $teacher); } return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'modelTeacher' => ArrayHelper::map(Teachers::find()->all(), 'id', 'userSurname', 'userName')]); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Teachers::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(['id' => $this->id]); $query->andFilterWhere(['like', 'userName', $this->userName]); $query->andFilterWhere(['like', 'userSurname', $this->userSurname]); $query->andFilterWhere(['like', 'nickName', $this->nickName]); $query->andFilterWhere(['like', 'phone', $this->phone]); $query->andFilterWhere(['like', 'imageFile', $this->imageFile]); $query->andFilterWhere(['like', 'dateBorn', $this->dateBorn]); $query->andFilterWhere(['like', 'sex', $this->sex]); $query->andFilterWhere(['like', 'education', $this->education]); $query->andFilterWhere(['like', 'email', $this->email]); $query->andFilterWhere(['like', 'id_department', $this->id_department]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getIdTeacher() { return $this->hasOne(Teachers::className(), ['id' => 'id_teacher']); }
/** * * @return \yii\db\ActiveQuery */ public function getTeachers() { return $this->hasMany(Teachers::className(), ['id' => 'id_teacher'])->viaTable('article_teacher', ['id_article' => 'id']); }
/** * Finds the Teachers model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Teachers the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Teachers::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getTeachers() { return $this->hasMany(Teachers::className(), ['id_department' => 'id']); }