/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Messages::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->sort->attributes['author'] = ['asc' => ['user.id' => SORT_ASC], 'desc' => ['user.id' => SORT_DESC]]; $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->joinWith('title'); $query->joinWith('user'); // grid filtering conditions $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'message', $this->message])->andFilterWhere(['like', 'user.username', $this->user_id])->andFilterWhere(['like', 'titles.name', $this->title_id]); return $dataProvider; }
public function actionMessageDisplay() { $query = new Query(); $provider = new ActiveDataProvider(['query' => Messages::find(), 'pagination' => ['pagesize' => 3]]); return $this->render('message-display', ['provider' => $provider]); }
/** * @return \yii\db\ActiveQuery */ public function getMessages() { return $this->hasMany(Messages::className(), ['user_id' => 'id']); }
/** * Finds the Messages model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Messages the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Messages::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }