1、文件目录

controllers 控制层
views 视图层

2、在controllers文件下新建 TestController.php 文件。

<?php

namespace app\controllers;

use yii\web\Controller;

class TestController extends Controller{
public function actionIndex(){
echo "string";
//$this->redirect(['site/index']);
//$this->goHome();
//$this->goBack();
//$this->refresh();
//return $this->render('index',['data'=>[1,2,3]]);//显示视图
return $this->renderPartial('index',['data'=>[1,2,3]]);//显示部分视图
}
public function actionMyUser(){
echo "myUser";//访问时应该index.php?r=test/my-user
}
}
?>

3、在views文件下新建 index.php 文件。

<?php
foreach ($data as $key => $value) {
echo $key.'--'.$value.'<br/>';//获取后台的分配的值
}
?>