我是yii的新手.我很难设置yii2.0高级并试图运行简单的hello程序.
我在后端/ Controllers/SiteController.php中添加了以下代码
public function actionSay($message = 'Hello')
{
return $this->render('say',['message' => $message]);
}
Run Code Online (Sandbox Code Playgroud)
然后,我使用以下代码在backend/views/site /中创建了say.php文件
<?php
use yii\helpers\Html;
?>
<?= Html::encode($message) ?>
Run Code Online (Sandbox Code Playgroud)
我输入../yii2hello/backend/web/index.php?r=site/say&message=Hello+World浏览器来访问该页面.
我收到了403错误 "you are not allowed to perform this action."
谁能告诉我问题出在哪里?
如果未定义访问此操作的权限,则会发生此错误.
您必须为您的操作添加权限,如下所示:
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'actions' => ['say'],
'allow' => true,
],
],
]
];
}
Run Code Online (Sandbox Code Playgroud)