I have a table called calls
and I need a single search input, to search in two columns, contact_number
and contact_name
.
How do I do this on Yii2?
_search.php
$form->field($model, 'searchstring')->textInput(['placeholder' => 'Search']);
common\models\CallsSearch.php
[['searchstring'], 'safe']
(..)
$query->orFilterWhere(['like', 'searchstring', $this->contact_name])
->orFilterWhere(['like', 'searchstring', $this->contact_number]);
controllers\CallsController.php
public function actionIndex()
{
$searchModel = new CallsSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}