首页 > 编程 > PHP > 正文

YiiFramework开发教程(1)配置环境及第一个应用

2020-03-22 20:23:24
字体:
来源:转载
供稿:网友
  • 准备工作:

    我用的开发环境是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 yiiiltersAccessControl;use yiiwebController;use yiiiltersVerbFilter;//类名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!';?>

    第四步:访问网址http://localhost/basic/web/index.php?r=zhyoulun/helloworld

    一种更纯净的展示方式

    将return $this->render('helloworld');改为return $this->renderPartial('helloworld');

    出处:http://blog.csdn.net/zhyoulun/article/details/40453559

    PHP编程

    郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。

  • 发表评论 共有条评论
    用户名: 密码:
    验证码: 匿名发表