YII框架学习-第一波

8 篇文章 0 订阅
6 篇文章 0 订阅

安装YII

   

php composer.phar create-project yiisoft/yii2-app-basic basic 2.0.13

   

安装好了之后,可以启动Apache服务器,并且访问YII框架:

http://localhost/DemoPage/Yii/basic/web/index.php

   

这是我安装好的目录文件:注意(最下面有个bat脚本,这个脚本的作用可以参考页面:

http://www.yiiframework.com/doc-2.0/guide-tutorial-console.html)

   

每个目录的作用,请看下面:

   

basic/ application base path
composer.json used by Composer, describes package information
config/ contains application and other configurations
console.php the console application configuration
web.php the Web application configuration
commands/ contains console command classes
controllers/ contains controller classes
models/ contains model classes
runtime/ contains files generated by Yii during runtime, such as logs and cache files
vendor/ contains the installed Composer packages, including the Yii framework itself
views/ contains view files
web/ application Web root, contains Web accessible files
assets/ contains published asset files (javascript and css) by Yii
index.php the entry (or bootstrap) script for the application
yii the Yii console command execution script

   

其中需要注意的是,所有的目录其实可以分为两个部分,一个是HTTP协议可以访问的目录,为web 目录, 其它的目录都不应该可以被http直接访问。

   

同时,web目录中有个启动文件,也就是index.php文件。

   

   

页面如下:(注意,该页面带有YII框架自带的一个DEBUG TOOL,使用方式可以参考:

https://github.com/yiisoft/yii2-debug/blob/master/docs/guide/README.md

   

   

   

下面介绍一下YII框架的架构方面的内容:

  • YII处理请求的流程:

       

       

    一个请求在框架中的生命周期如下:

       

       

    下面是对请求生命周期的详细描述:

  1. A user makes a request to the entry script web/index.php.
  2. The entry script loads the application configuration and creates an application instance to handle the request.
  3. The application resolves the requested route with the help of the request application component.
  4. The application creates a controller instance to handle the request.
  5. The controller creates an action instance and performs the filters for the action.
  6. If any filter fails, the action is cancelled.
  7. If all filters pass, the action is executed.
  8. The action loads a data model, possibly from a database.
  9. The action renders a view, providing it with the data model.
  10. The rendered result is returned to the response application component.
  11. The response component sends the rendered result to the user's browser.

       

   

   

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值