在SiteController.php中增加方法say():
public function actionSay($message="everyone")
{
$message = "Miss.jiang";
return $this->render('say', ['message'=>$message]); //渲染视图文件并传参$message
}
在根目录的view下新建文件say.php:
<?php
/* @var $this yii\web\View */
use yii\helpers\Html;
$this->title = 'Say';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-about">
<h1><?= Html::encode($this->title) ?></h1>
<p>
Hello, <?= $message ?>
</p>
</div>
最后,在main.php中新增导航栏say。
['label' => 'Say', 'url' => ['/site/say']],
运行结果: