yii2 : 致命错误 $this

yii2 : Fatal error $this

我正在尝试 运行 "yii2-angular-seed-master" 在我的本地机器上。 我从 https://github.com/seedss/yii2-angular-seed.

下载

但是当我尝试 运行 这个 URL 时。 http://localhost/harry/yii2-angular-seed-master/frontend/views/site/

它给了我以下错误。

Fatal error: Using $this when not in object context in /var/www/harry/yii2-angular-seed-master/frontend/views/site/index.php on line 3

----------------------
code for views/site/index.php
<?php
/* @var $this yii\web\View */
    $this->title = 'My Yii Application';
?>
-----------------------
SiteController.php

<?php
namespace frontend\controllers;
//namespace app\controllers;
use Yii;
use common\models\LoginForm;
use frontend\models\PasswordResetRequestForm;
use frontend\models\ResetPasswordForm;
use frontend\models\SignupForm;
use frontend\models\ContactForm;
use yii\base\InvalidParamException;
use yii\web\BadRequestHttpException;
use yii\web\Controller;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use yii\web\NotFoundHttpException;

    public function actionIndex()
    {
            return $this->render('index');
    }

请告诉我上面的代码有什么问题。

$this in /var/www/harry/yii2-angular-seed-master/frontend/views/site/index.php 是 View class 的实例。这与 Yii1 中的 $this 不同,它曾经指代控制器。
在每个视图中删除 $this 绝对不是要走的路,因为这正是 Yii2 的工作方式。

控制器将创建该视图实例,因此您不应直接调用视图文件。相反,按如下方式调用 url:http://localhost/harry/yii2-angular-seed-master/frontend/site/index(根据您的 .htaccess 重写规则,如该存储库的自述文件中所述)。

更多信息:
http://www.yiiframework.com/doc-2.0/guide-structure-views.html http://www.yiiframework.com/doc-2.0/yii-web-view.html