Esempio n. 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Joke::find()->where(['<>', 'joke.active', 3]);
     $query->joinWith(['person']);
     //$query->andWhere(['<>', 'joke.active', 3]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->sort->attributes['nick'] = ['asc' => ['person.nick' => SORT_ASC], 'desc' => ['person.nick' => SORT_DESC]];
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     /*$query->andFilterWhere(['id'=>$this->id]);
       $query->andFilterWhere(['person_id'=>$this->person_id]);*/
     $query->andFilterWhere(['id' => $this->id, 'create_date' => $this->create_date, 'views' => $this->views, 'active' => $this->active]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'person_id', $this->person_id]);
     /*$query->joinWith(['person' => function ($q) {
           $q->where('person.nick LIKE "%' . $this->nick . '%"');
       }]);*/
     $query->andFilterWhere(['like', 'person.nick', $this->nick]);
     return $dataProvider;
 }
Esempio n. 2
0
 public function getJoke($joke_id)
 {
     return Joke::find()->where(['id' => $joke_id])->one();
 }
Esempio n. 3
0
 /**
  * Finds the Joke model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Joke the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Joke::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Esempio n. 4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getJokes()
 {
     return $this->hasMany(Joke::className(), ['id' => 'joke_id'])->viaTable('joke_category', ['category_id' => 'id']);
 }