title: Yii2 - list every post - coding error
body: <p>I am new in Yii2 and I made a site where i can write posts, view them, delete them etc... </p>
  
  <p>I want to list every post from a DB on one page as a "timeline" </p>
  
  <p>My code does not list any error simply just show the very first record only. </p>
  
  <p>Here is my code from (views) index.php </p>
  
  <pre><code>        &lt;?php
  
  use yii\helpers\Html;
  use yii\widgets\ListView;
  
  /* @var $this yii\web\View */
  /* @var $searchModel frontend\models\search\TweetSearch */
  /* @var $dataProvider yii\data\ActiveDataProvider */
  
  $this-&gt;title = 'My tweets';
  
  ?&gt;
  &lt;div class="tweet-model-index"&gt;
  
      &lt;h1 class="text-center"&gt;&lt;?= Html::encode($this-&gt;title) ?&gt;&lt;/h1&gt;
  
  
      &lt;p class="text-center"&gt;
          &lt;?= Html::a('New Tweet', ['create'], ['class' =&gt; 'btn btn-success']) ?&gt;
      &lt;/p&gt;
  
      &lt;?php
  
      $con = \Yii::$app-&gt;db;
  
      $sql = $con-&gt;createCommand("SELECT * FROM tweet ORDER BY created_at DESC");
  
      $tweets = $sql-&gt;queryAll();
  
      if(!$tweets)
          echo '&lt;h2&gt; This is empty &lt;/h2&gt;';
       else{
             foreach($tweets as $tweet){
         ?&gt;
  
  
  
      &lt;hr&gt;
      &lt;div class="container-fluid"&gt;
          &lt;div class="col-md-8 col-md-offset-2"&gt;
              &lt;h2 class="text-left"&gt;
                  &lt;?php echo $tweet['tweet_title']; ?&gt; 
                  &lt;br&gt;&lt;small&gt;Author: &lt;b&gt;&lt;?php echo $tweet['author_id'];?&gt; &lt;/b&gt;Created at: &lt;b&gt;&lt;?php echo date(($tweet['created_at']));?&gt;&lt;/b&gt;
                      &lt;br&gt;Updated at: &lt;b&gt;&lt;?php echo date(($tweet['updated_at']));?&gt;
                  &lt;/small&gt;
              &lt;/h2&gt;
  
                  &lt;p class="text-left"&gt;
                  &lt;?= Html::a('Update', ['update', 'id' =&gt; $tweet['tweet_id']], ['class' =&gt; 'btn btn-primary']) ?&gt;
                  &lt;?= Html::a('View', ['view', 'id' =&gt; $tweet['tweet_id']], ['class' =&gt; 'btn btn-primary']) ?&gt;
                  &lt;?= Html::a('Delete', ['delete', 'id' =&gt; $tweet['tweet_id']], [
                                          'class' =&gt; 'btn btn-danger',
                                          'data' =&gt; [
                                          'confirm' =&gt; 'Are you sure you want to delete this item?',
                                          'method' =&gt; 'post',
                                          ],
                                      ]) ?&gt;
                  &lt;/p&gt;
  
  
  
          &lt;/div&gt;
  
  
      &lt;/div&gt;
  
  &lt;/div&gt;
  &lt;?php endforeach; ?&gt;
  &lt;?php endif; ?&gt;
  </code></pre>
  
  <p>May i ask You guys, how can I count the views on each post? </p>
  
  <p>I tried this on my TweetController but doesn't work. </p>
  
  <pre><code>public function actionView($id)
  {
      $this-&gt;render('view',array(
          'model'=&gt;$this-&gt;loadModel($id));
  }
  </code></pre>