Hi guys, I want to ask, how can I pass data to a model search and filter on field with this data. I have the following model,
<?php
namespace app\modules\menus\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\modules\menus\models\MenuCategories;
/**
* MenuCategoriesSearch represents the model behind the search form about `app\modules\menus\models\MenuCategories`.
*/
class MenuCategoriesSearch extends MenuCategories
{
public function rules()
{
return [
[['id', 'menu'], 'integer'],
[['name', 'category_ids'], 'safe'],
];
}
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
public function search($params)
{
$query = MenuCategories::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query->andFilterWhere([
'id' => $this->id,
'menu' => $this->menu,
]);
$query->andFilterWhere(['like', 'name', $this->name])
->andFilterWhere(['like', 'category_ids', $this->category_ids]);
return $dataProvider;
}
}
but I want to select only those results that have field name = 1 or name= 0 … depending on what I need? In the previous version, these data are fed into the grid