Created
August 14, 2019 03:30
-
-
Save 4t4nner/8256b02d4d70d5e662a5224cd9098f95 to your computer and use it in GitHub Desktop.
unknown property error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace common\modules\news\models; | |
use Yii; | |
use yii\base\Model; | |
use yii\data\ActiveDataProvider; | |
/** | |
* NewsSearch represents the model behind the search form of `common\modules\news\models\News`. | |
*/ | |
class NewsSearch extends News | |
{ | |
/** | |
* @inheritdoc | |
*/ | |
public function rules() | |
{ | |
return [ | |
[['id', 'category_id', 'created_by', 'updated_by', 'sort', 'status'], 'integer'], | |
[['title', 'slug', 'short_text', 'full_text', 'image', 'created_at', 'updated_at', 'lang'], 'safe'], | |
]; | |
} | |
/** | |
* @inheritdoc | |
*/ | |
public function scenarios() | |
{ | |
// bypass scenarios() implementation in the parent class | |
return Model::scenarios(); | |
} | |
/** | |
* Creates data provider instance with search query applied | |
* | |
* @param array $params | |
* | |
* @return ActiveDataProvider | |
*/ | |
public function search($params) | |
{ | |
$query = News::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, | |
'category_id' => $this->category_id, | |
'created_at' => $this->created_at, | |
'updated_at' => $this->updated_at, | |
'created_by' => $this->created_by, | |
'updated_by' => $this->updated_by, | |
'sort' => $this->sort, | |
'status' => $this->status, | |
]); | |
$query->andFilterWhere(['like', 'title', $this->title]) | |
->andFilterWhere(['like', 'slug', $this->slug]) | |
->andFilterWhere(['like', 'short_text', $this->short_text]) | |
->andFilterWhere(['like', 'full_text', $this->full_text]) | |
->andFilterWhere(['like', 'image', $this->image]) | |
->andFilterWhere(['like', 'lang', $this->lang]); | |
return $dataProvider; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment