H
H
Hancock_8882016-06-30 09:45:07
Yii
Hancock_888, 2016-06-30 09:45:07

Is it possible to do a collection search in Yii2?

Good afternoon, could you tell me if it is possible to make a selection, for example, of an article with status two. article ----------------------- id title status description And then search this collection ($articles ) , for example in titles (title) - %article %?
$articles = Article::findAll(['status' => 2]);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ilya, 2016-06-30
@Hancock_888

And what's the problem with doing a search right away?

$articles = Article::findAll([
'status' => 2.
'title' => '...'
]);

---
Well, or if for some reason you are not satisfied with the option above, you can use array_filter for PHP.

M
Maxim Timofeev, 2016-06-30
@webinar

$query = 'поисковый запрос';
$articles = Article::find()
->andWhere(['status' => 2])
->andWhere(['like','title',$query])
->all();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question