本章节讨论如何在应用中创建“Hello”页面

创建Action

controllers/SiteController.php中:

<?php

namespace app\controllers;

use yii\web\Controller;

class SiteController extends Controller
{
    // ...existing code...

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

创建视图

views/site/say.php中:

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

试试看吧:

http://hostname/index.php?r=site/say&message=Hello+World