使用未定义的常量“消息” - 假设“消息”'在Yii框架中

时间:2015-02-18 14:35:38

标签: php yii

我是Yii框架的新手。刚刚开始学习Yii 2.0,但是我收到了以下错误。

在controllers / SiteController.php中编写了以下代码

class SiteController extends Controller
{
// ...existing code...
public function actionSay($message = ’Hello’)
{
return $this->render(’say’, [’message’ => $message]);
}
}

并在views / ControllerID / ViewName.php中编写了以下代码

<?php
use yii\helpers\Html;
?>
<?= Html::encode($message) ?>

当我在浏览器“http://localhost/web/index.php?r=site/say&message=Hello+World”中运行此行时 获得以下错误

PHP Notice – yii\base\ErrorException

Use of undefined constant ’message’ - assumed '’message’'
1. in C:\xampp\htdocs\basic\controllers\SiteController.php at line 99
90919293949596979899100101    }

    public function actionAbout()
    {
        return $this->render('about');
    }

    public function actionSay($message = ’Hello’)
    {
        return $this->render('say', [’message’ => $message]);
    }
}
2. in C:\xampp\htdocs\basic\controllers\SiteController.php – yii\base\ErrorHandler::handleError(8, 'Use of undefined constant ’messa...', 'C:\xampp\htdocs\basic\controller...', 99, ...) at line 99
93949596979899100101    {
        return $this->render('about');
    }

    public function actionSay($message = ’Hello’)
    {
        return $this->render('say', [’message’ => $message]);
    }
}

任何人都可以帮我解决这个错误。

1 个答案:

答案 0 :(得分:0)

REPLACE:返回$ this-&gt; render('say',['message'=&gt; $ message]); WITH:返回$ this-&gt;渲染(&#39;说&#39;,[&#39; message&#39; =&gt; $ message]);