我正在尝试在本地计算机上运行“ yii2-angular-seed-master”。我从https://github.com/seedss/yii2-angular-seed下载了它。
但是,当我尝试运行此URL时。http:// localhost / harry / yii2-angular-seed-master / frontend / views / site /
它给了我以下错误。
致命错误:在第3行的/var/www/harry/yii2-angular-seed-master/frontend/views/site/index.php中的对象上下文中不使用$ this
----------------------
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
在/var/www/harry/yii2-angular-seed-master/frontend/views/site/index.php中是View
该类的实例。这与$this
Yii1中的不同,Yii1中以前是指控制器。绝对不是
删除$this
所有视图的方法,因为这就是Yii2的工作方式。
控制器将创建该View实例,因此您不应直接调用该视图文件。而是,按如下方式调用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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句