Why doesn't the search in the controller, Yii2?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
26 views
$model = new SearchFile();// form if ($model->load(Yii::$app->request->post()) && $model->validate()) { $search = $model->search_file; $query = File::find()->where(['like', 'name_file', $search])->andWhere(['like', 'type', $search]); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => 10]); $file = $query->offset($pages->offset) ->limit($pages->limit) ->all(); // this code displays an empty array } else { // this code rabotat $query = File::find(); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => 10]); $file = $query->offset($pages->offset) ->limit($pages->limit) ->all(); }

Dannie with the formation but there is no difference with bazi difference. There is no error and not showing.
What could be the problem?

p.s.
Model search
public $search_file; public function rules() { return [ [['search_file'], 'trim'], ['search_file', 'string', 'max' => 191] ]; } /** * {@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 = File::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider([ 'query' => $query, 'pagination' => [ 'pageSize' => 10, ], 'sort' => [ 'defaultOrder' => [ 'created' => 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->andFilterWhere(['like', 'name_file', $this->search_file]); // ->andFilterWhere(['like', 'type', $this->search_file]); the field return $dataProvider; }

by | 26 views

1 Answer

0 like 0 dislike
->where(['like', 'name_file', $search])->andWhere(['like', 'type', $search]);

You understand that You have name_file and type must contain the $search? In my opinion it is very strange. If should be the same as someone or something, then "or" and not "and".
I find it very hard to imagine what would type something stored in a string. And then there's the type which partially contains the same sequence of name_file.
by

Related questions

0 like 0 dislike
1 answer
asked May 20, 2019 by AlexWeb6667
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
110,608 questions
257,187 answers
0 comments
40,796 users