我需要在yii2中从单个表的多个表字段中搜索

时间:2016-10-24 08:29:34

标签: php yii2

$data = \app\models\Events::find()->
         where(['event_code''event_name'[] =>$_POST['event_code''event_name'] ])->all();

return $this->render('search',['data'=>$data]);

我需要在event_codeevent_name进行搜索。我该怎么办?

2 个答案:

答案 0 :(得分:0)

您可以使用andWhere添加多个条件

$data = \app\models\Events::find()->where(['=','event_code',$_POST['event_code']])->andWhere(['=','event_name',$_POST['event_name']])->all();

答案 1 :(得分:0)

试试这个:

$data = \app\models\Events::find()->where(['event_code' => $_POST['event_code'], 'event_name' => $_POST['event_name']])->all();