I'm struggling to work out how to use a filter in my grid when it's generated from an SqlDataProvider.
Currently my model works like so:
$sql = 'SELECT * FROM my_table';
$provider = new SqlDataProvider([
'sql' => $sql,
'params' => [':start' => $param1, ':end' => $param2],
'totalCount' => $count,
'pagination' => [
'pageSize' => 100
],
]);
return $provider;
When there isn't an active record how should this be done? The search models seem to all be based of AR and calling in the controller:
$searchModel->search(Yii::$app->request->queryParams);
Where $searchModel function begins like this:
public function search($params)
{
$query = myTable::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
...
I have started to change the search() function to be more like this, but not sure I'm going about it the right way:
$query = new Query;
$query->select('*')
->from('my_table');
// add conditions that should always apply here
$dataProvider = new SqlDataProvider([
'sql' => $query,
'pagination' => [
'pageSize' => 100
],
]);
As it errors with
preg_match() expects parameter 2 to be string, object given