准备工作:
我用的开发环境是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文件
<?phpnamespace appcontrollers;use Yii;use yiiiltersAccessControl;use yiiwebController;use yiiiltersVerbFilter;//类名ZhyoulunController必须和文件名对应html' target='_blank'>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”对应
<?phpecho 'hello world!';?>
一种更纯净的展示方式
将return $this->render('helloworld');改为return $this->renderPartial('helloworld');
出处:http://blog.csdn.net/zhyoulun/article/details/40453559
PHP编程郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。
新闻热点
疑难解答