public function actionData() { if (($model = Students::find()->where(['user_id' => Yii::$app->user->identity->id])->one()) == null) { $model = new Students(); } if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['data']); } else { return $this->render('data', ['model' => $model]); } }
protected function findModel($id) { if (($model = Students::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Students::find(); // add conditions that should always apply here $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; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'middleName', $this->middleName])->andFilterWhere(['like', 'surname', $this->surname])->andFilterWhere(['like', 'phone', $this->phone])->andFilterWhere(['like', 'address', $this->address])->andFilterWhere(['like', 'education', $this->education])->andFilterWhere(['like', 'specialty_one', $this->specialty_one])->andFilterWhere(['like', 'specialty_one_docs', $this->specialty_one_docs])->andFilterWhere(['like', 'specialty_two', $this->specialty_two])->andFilterWhere(['like', 'specialty_two_docs', $this->specialty_two_docs])->andFilterWhere(['like', 'specialty_three', $this->specialty_three])->andFilterWhere(['like', 'specialty_three_docs', $this->specialty_three_docs]); return $dataProvider; }
<?php use yii\helpers\Html; use yii\widgets\DetailView; use backend\modules\students\models\Students; $this->title = $model->surname; $this->params['breadcrumbs'][] = ['label' => 'Слушатели', 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; ?> <div class="box box-primary"> <div class="box-body"> <?php echo DetailView::widget(['model' => $model, 'attributes' => ['name', 'middleName', 'surname', ['attribute' => 'user_id', 'label' => 'Email', 'value' => Students::studentsEmail($model->user_id)], 'phone', 'address', 'education:ntext', 'specialty_one', 'specialty_one_docs', 'specialty_two', 'specialty_two_docs', 'specialty_three', 'specialty_three_docs', 'created_at:date', 'updated_at:date']]); ?> </div> </div>