Call Model Method In Controller In Yii
<p>Hello Friends I am new to Yii2 Framework. </p>

<p>i am writing following code as specified in mention filename still....</p>

<p>While i am calling model method then does not showing output showing <strong>500 error</strong> in console </p>

<p>Is Any Mistake in code then please mention here ..</p>

<p><strong>SiteController.php</strong></p>

<pre><code>&lt;?php

use yii\web\Controller;
use yii\data\Pagination;
use app\models\Site;

class SiteController extends CController
{
    // Define an action. actionIndex is a default action
    public function actionIndex()
    {   
        $data =  Site::models()-&gt;getData();    
        $this-&gt;render('view',array(
        'data'=&gt;$data,
        ));

        // $this-&gt;render('view');
        }
  }
</code></pre>

<p><strong>Site.php - Model</strong></p>

<pre><code>&lt;?php
namespace app\models;

use yii\db\ActiveRecord;

    class Site extends ActiveRecord
    {
        public function getData() {
              $connection = Yii::app()-&gt;db;
              $command = $connection-&gt;createCommand("Select * from site");
              return $caterow = $command-&gt;queryAll();
        }
        public static function tableName()
        {
            return 'site';
        }
    }
</code></pre>