Yii Framework2.0开发教程(1)配置环境及第一个应用HelloWorld
2014-10-25 16:35
1206 查看
准备工作:
我用的开发环境是windows下的apache+mysql+php
编辑器不知道该用哪个好,暂时用dreamweaver吧
我自己的http://localhost/对应的根目录是E:/website/localhost/
![](https://img-blog.csdn.net/20141025161539037?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemh5b3VsdW4=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
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
将下载下来的压缩包解压到网站根目录中
![](https://img-blog.csdn.net/20141025161525390?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemh5b3VsdW4=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
访问网址http://localhost/basic/requirements.php可以查看自己搭建的环境是否符合yii的要求
![](https://img-blog.csdn.net/20141025161512658?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemh5b3VsdW4=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
设置参数cookieValidationKey,我设置的是”zhyoulun“,随便设置
![](https://img-blog.csdn.net/20141025161750327?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemh5b3VsdW4=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
访问网址http://localhost/basic/web/验证是否一切准备就绪
![](https://img-blog.csdn.net/20141025161941430?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemh5b3VsdW4=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
开始写HelloWorld
第一步、在controllers文件夹下新建ZhyoulunController.php文件
第二步、在views文件夹下新建zhyoulun文件夹,这个需要和ZhyoulunController.php中的“Zhyoulun”对应
第三步、在views/zhyoulun中新建helloworld.php文件,这个需要和ZhyoulunController类中的公共函数actionHelloworld()里的“Helloworld”以及return $this->render('helloworld');里的“helloworld”对应
第四步:访问网址http://localhost/basic/web/index.php?r=zhyoulun/helloworld
![](https://img-blog.csdn.net/20141025163118783?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemh5b3VsdW4=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
一种更纯净的展示方式
将return $this->render('helloworld');改为return $this->renderPartial('helloworld');
![](https://img-blog.csdn.net/20141025163302039?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemh5b3VsdW4=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
参考:http://www.yiichina.com/guide/2/start-hello
转载请注明出处:http://blog.csdn.net/zhyoulun/article/details/40453559
我用的开发环境是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');
参考:http://www.yiichina.com/guide/2/start-hello
转载请注明出处:http://blog.csdn.net/zhyoulun/article/details/40453559
相关文章推荐
- 【Android】简单详细的安卓开发环境配置及运行第一个程序Helloworld
- Yii Framework 开发教程(1) 第一个应用Hello World
- Yii Framework 开发教程(1) 第一个应用Hello World
- AIR2.0入门教程:新特性介绍以及开发环境的配置
- 在Windows下应用AppServ快速配置PHP开发环境
- Eclipse3.0.1+Myeclipse3.8.2+tomcat5开发第一个struts应用(配置篇
- Appeon Web应用在Apache2.0+EAServer5.2环境中的配置方法
- 应用Eclipse开发GIS之路-应用ArcIMS ADF for Java环境配置篇
- [原创]Wicket 1.4 开发手记(一) helloworld与环境配置
- MyEclipse 8.5 开发环境配置,汉化,Aptana2.0插件,SVN 插件,Flex Builder 3/4 插件安装
- 配置Silverlight2.0的开发环境
- 黑莓开发者的第一个BlackBerry应用开发--搭建环境
- Nintendo DS(NDS) 开发环境配置教程
- MyEclipse 8.5 开发环境配置、插件安装、汉化、Aptana2.0插件,SVN 插件,Flex Builder 3/4 插件安装
- 【原创】ASP.NET Web 应用开发实战快速上手系列 1——配置环境及预备知识(框架、VS、C#)
- PHP开发环境配置(MySQL数据库安装图文教程)
- Asianux2.0 Linux 中开发环境配置
- Flash教程:安装和配置JDK开发环境
- 在Ubuntu下配置C/C++ 开发环境 —— HelloWorld !
- ★★ MyEclipse 8.5 开发环境配置、插件安装、汉化、Aptana2.0插件,SVN 插件,Flex Builder 3/4 插件安装