/** * 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; }