コード例 #1
0
ファイル: NewsSearch.php プロジェクト: aekkapun/yii2-news
 public function searchText($text)
 {
     $query = News::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $query->andFilterWhere(['like', 'title', $text])->orFilterWhere(['like', 'summary', $text])->orFilterWhere(['like', 'content', $text]);
     return $dataProvider;
 }
コード例 #2
0
 /**
  * Finds the News model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return News the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = News::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }