Answer the question
In order to leave comments, you need to log in
Does the Yii2 Behavior have a changing SELECT query in the database?
Hello, I want to automatically drive in certain WHERE conditions in each selection from the model, I think that it is completely possible to do this through behaviors, but I can’t help but find events that would catch SELECT queries in the model, and be able to customize this query.
Answer the question
In order to leave comments, you need to log in
I could be wrong, but it looks like this
public function actions()
{
$actions = parent::actions();
$actions['index']['prepareDataProvider'] = [$this, 'prepareDataProvider'];
return $actions;
}
public function prepareDataProvider()
{
return new ActiveDataProvider([
'query' => MyModel::find()->andWhere(['some_field' => $fieldValue])
]);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question