Performing multiple queries in yii2

I am performing a query in yii2 which requires two conditions . I have tried"

$query = Evidence::find()
->where(['case_ref'=>$id && 'evidence_type'="picture"]);
$dataProviderb = new ActiveDataProvider([
'query' => $query,
    ]);

But I keep on getting error of unexpected = and expecting ]. How can I perform multiple queries in yii2

Answers


I would always recommend use GII's crud generator after creating a model (or even generating by GII) and, after that, made your adjusts and delete what you not going to use.

Since i can't find a example of the search in the docs, here is a sample:

$query = Evidence::find()
    ->andFilterWhere(['case_ref' => $id])
    ->andFilterWhere(['evidence_type' => 'picture']);

$dataProviderb = new ActiveDataProvider([
    'query' => $query,
]);

Not sure where you calling this... usually you have a modelSearch that already loaded input from get parameters. So instead of $id you should probably use $this->id. Let me know how it works for you.


Need Your Help

ThreadAbortException (WebClient using DownloadFile to grab file from server)

c# .net asp.net exception-handling httpresponse

Referencing my Earlier Question, regarding downloading a file from a server and handling exceptions properly. I am positive that I had this solved, then in classic programming fashion, returned days