Using yii2, I created a model and CRUD using gii.
I want to use foreach or while loop in my VIEW to display data in the following format
For each row in the database table
echo("addMarker($lat_field, $lon_field);\n");
I have an index page that is displayed using the next controller action.
public function actionIndex()
{
$this->layout = 'directory';
$searchModel = new ShopDirectorySearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
I can use the following to display data using a listview that displays all the data / rows in the database, but it has html around it and obviously does not display in the format I would like.
<?= ListView::widget([
'dataProvider' => $dataProvider,
'itemOptions' => ['class' => 'col-xs-6 col-sm-3'],
'itemView' => '_index',
]);?>
source
share