title: Yii2 display data using for each loop
body: <p>Using yii2 I have created a Model and CRUD using gii.</p>
  
  <p>I want to use a foreach or while loop in my VIEW to display the data in the following format</p>
  
  <p>For each row in database table</p>
  
  <pre><code>echo("addMarker($lat_field, $lon_field);\n");
  </code></pre>
  
  <p>I have an index page which is rendered using the following controller action.</p>
  
  <pre><code>    public function actionIndex()
  {
      $this-&gt;layout = 'directory';
  
      $searchModel = new ShopDirectorySearch();
      $dataProvider = $searchModel-&gt;search(Yii::$app-&gt;request-&gt;queryParams);
  
      return $this-&gt;render('index', [
          'searchModel' =&gt; $searchModel,
          'dataProvider' =&gt; $dataProvider,
      ]);
  }
  </code></pre>
  
  <p>I can use the following to display the data using listview which displays all the data/rows within database however it has html around it and obviously isn't outputted in the format I wish it to be.</p>
  
  <pre><code>    &lt;?=  ListView::widget([
   'dataProvider' =&gt; $dataProvider,
   'itemOptions' =&gt; ['class' =&gt; 'col-xs-6 col-sm-3'],
   'itemView' =&gt; '_index',
  ]);?&gt;
  </code></pre>