I try this, but the data is not transferred \ controller

public function actionIndex ()

{ $categories = Categories::find()->asArray()->all(); print_r($categories); return $this->render('index', compact('categories')); } 

index.php

 <?php foreach ($categories as $prod) :?> <div class="product"> <a href="#" class="product_img"> <img src="images/<? echo $prod['img'];?> </a> </div> <?php endforeach;?> 
  • Good evening. Are you sure that the request returns a non-empty response? And how do you display data at index? - user216615
  • @slo_nik Yes, on other pages it is displayed normally. It does not display print_r result - zip_file
  • If print_r () is empty, then the request returns nothing. And so the view is not transmitted - user216615
  • @slo_nik: But the query has returned data, but I don’t understand why the results are displayed on other pages, but not at index - zip_file
  • In print_r () is the result of the query? How do you display data at index? - user216615

1 answer 1

  return $this->render('index', ['categories' => $categories]);