I LIstView trying to organize the work of LIstView with links and greedy download. This is how I organize greedy loading.

 $allGods=Gods::find()->with('prise','images','addfeilds')->all(); 

Here so I betray in representation

  <?= ListView::widget([ 'dataProvider' => $productsDataProvider, 'itemView' => '_gods', 'viewParams' => [ 'allGods' => $allGods,] ]) ?> 

I try to use it like this

 var_dump($model->images) 

I get an additional sql query. I understand that I'm doing something wrong. Do not tell me how to correct?

    2 answers 2

    IMHO, if you pass the data provider to the ListView, then transferring 'allGods' => $ allGods is unnecessary.

    Here is an example.

     // Действие в контроллере public function actionGods() { $provider = new ActiveDataProvider([ 'query' => Gods::find()->with('prise','images','addfeilds') ]); $this->render('view', ['provider' => $provider]); } // Вызов ListView во view <?= ListView::widget([ 'itemView' => '_gods', 'dataProvider' => $provider ]); 

      with on yii2 creates a separate request with where in ... For the request to be one with joins, specify joinWith() instead of with()