准备工作:
我用的开发环境是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 appcontrollers; use Yii; use yiifiltersAccessControl; use yiiwebController; use yiifiltersVerbFilter; //类名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');
參考:http://www.yiichina.com/guide/2/start-hello
转载请注明出处:http://blog.csdn.net/zhyoulun/article/details/40453559