准备工作:
我用的开发环境是windows下的apache+mysql+php
编辑器不知道该用哪个好,暂时用dreamweaver吧
我自己的Http://localhost/对应的根目录是E:/website/localhost/

yii的下载地址是https://github.com/yiisoft/yii2/releases/download/2.0.0/yii-basic-app-2.0.0.tgz
备用下载地址:http://download.csdn.net/detail/u012314976/8080883
将下载下来的压缩包解压到网站根目录中

访问网址http://localhost/basic/requirements.php可以查看自己搭建的环境是否符合yii的要求

设置参数cookieValidationKey,我设置的是”zhyoulun“,随便设置

访问网址http://localhost/basic/web/验证是否一切准备就绪

开始写HelloWorld
第一步、在controllers文件夹下新建ZhyoulunController.PHP文件
<?php
namespace app\controllers;
use Yii;
use yii\filters\AccessControl;
use yii\web\Controller;
use yii\filters\VerbFilter;
//类名ZhyoulunController必须和文件名对应
class ZhyoulunController extends Controller
{
public function actionHelloworld()
{
return $this->render('helloworld');
}
}
第二步、在views文件夹下新建zhyoulun文件夹,这个需要和ZhyoulunController.php中的“Zhyoulun”对应
第三步、在views/zhyoulun中新建helloworld.php文件,这个需要和ZhyoulunController类中的公共函数actionHelloworld()里的“Helloworld”以及return $this->render('helloworld');里的“helloworld”对应
<?php echo 'hello world!'; ?>
第四步:访问网址http://localhost/basic/web/index.php?r=zhyoulun/helloworld

一种更纯净的展示方式
将return $this->render('helloworld');改为return $this->renderPartial('helloworld');
