Answer the question
In order to leave comments, you need to log in
Why has the number of requests increased?
To implement filters in the gridview, I need to get model data several times. I'm trying to organize the gridview itself as follows
[
'attribute'=>'title',
'header'=>'Type',
'filterType'=>GridView::FILTER_SELECT2,
'filter'=> $models->type,
'filterWidgetOptions'=>[
'pluginOptions'=>['allowClear'=>true],
],
'filterInputOptions'=>['placeholder'=>Html::encode('Select Type')]
],
[
'attribute'=>'provider',
'filterType'=>GridView::FILTER_SELECT2,
],
[
'attribute'=> 'quantity',
'filterType'=>GridView::FILTER_SELECT2,
'filter'=> $models->quantitys,
'filterWidgetOptions'=>[
'pluginOptions'=>['allowClear'=>true],
],
'filterInputOptions'=>['placeholder'=>Html::encode('Select Quantity')]
],
public function __construct($config = [])
{
$this->products=$this::find()->asArray()->all();
parent::__construct($config);
}
public function getType(){
return ArrayHelper::map($this->products,'title','title');
}
/**
* @return array
*/
public function getProviders(){
return ArrayHelper::map($this->products,'provider','provider');
}
/**
* @return array
*/
public function getQuantitys(){
return ArrayHelper::map($this->products,'quantity','quantity');
}
Answer the question
In order to leave comments, you need to log in
The number of requests has increased from the fact that you are making a request in the model constructor. Accordingly, when you make a selection of models (for GridView), you get an array of models and a constructor with a request is called for each of them. If you want to solve the problem - remove the request from the constructor to another place
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question