Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
9c41d879
Commit
9c41d879
authored
Jun 17, 2014
by
riverlet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
translated.
parent
025b9f6a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
62 deletions
+57
-62
start-workflow.md
docs/guide-zh-CN/start-workflow.md
+57
-62
No files found.
docs/guide-zh-CN/start-workflow.md
View file @
9c41d879
运行应用程序
运行应用程序
====================
====================
Yii 安装后,就有了一个可以运行的 Yii 应用程序
了
,你可以通过 URL
`http://hostname/basic/web/index.php`
或
Yii 安装后,就有了一个可以运行的 Yii 应用程序,你可以通过 URL
`http://hostname/basic/web/index.php`
或
`http://hostname/index.php`
访问它,具体取决于你的配置。本章将介绍此应用程序的内置功能,代码的组织方式以及总体上程序是
`http://hostname/index.php`
访问它,具体要取决于你的配置。本章将介绍此应用程序的内置功能,代码的组织方式以及总体上程序是怎样处理请求
怎样处理请求
的。
的。
> Info: 为简单起见,这个“入门”教程假设你已经将 `basic/web` 设置为了 Web 服务器的文档根目录。访问此程序的是类似
> Info: 为简单起见,这个“入门”教程假设你已经将 `basic/web` 设置为了 Web 服务器的文档根目录。访问此程序的是类似
`http://hostname/index.php`
的 URL 。请根据你的实际情况,在下文描述中作相应调整。
`http://hostname/index.php`
的 URL 。请根据你的实际情况,在下文描述中作相应调整。
Functionality
<a name="functionality"></a>
功能
<a name="functionality"></a>
-------------
-------------
The basic application installed contains four pages:
安装的基础应用程序包含四个页面:
*
The homepage, displayed when you access the URL
`http://hostname/index.php`
,
*
首页,访问 URL
`http://hostname/index.php`
时显示,
*
the "About" page,
*
"About" 页面,
*
the "Contact" page, which displays a contact form that allows end users to contact you via email,
*
"Contact" 页面,显示一个联络表单,允许终端用户通过电子邮件与你联系。
*
and the "Login" page, which displays a login form that can be used to authenticate end users. Try logging in
*
还有 "Login" 页面,显示一个登录表单,用于验证终端用户。请尝试使用“admin/admin”登录,你将发现主菜单上原来的“Login”变成了“Logout”。
with "admin/admin", and you will find the "Login" main menu item will change to "Logout".
These pages share a common header and footer. The header contains a main menu bar to allow navigation
这些页面共享一个通用的 header 和 footer。Header 含有一个主菜单,可以导航到不同的页面。
among different pages.
You should also see a toolbar at the bottom of the browser window.
你应该还会在浏览器窗口的最下面发现有一个工具条。这是一个 Yii 提供的很有用的
[
调试工具
](
tool-debugger.md
)
,它会记录并显示很多调试信息,
This is a useful
[
debugger tool
](
tool-debugger.md
)
provided by Yii to record and display a lot of debugging information, such as log messages, response statuses, the database queries run, and so on.
例如日志消息,响应状态,数据库执行的查询等等。
Application Structure
<a name="application-structure"></a>
应用程序结构
<a name="application-structure"></a>
---------------------
---------------------
The most important directories and files in your application are (assuming the application's root directory is
`basic`
):
在你的应用程序中最重要的目录和文件是(假设程序的根目录是
`basic`
):
```
```
basic/
application base path
basic/
应用程序根目录
composer.json
used by Composer, describes package information
composer.json
用于 Composer,描述包的信息
config/
contains application and other configurations
config/
包含应用程序及其他配置信息。
console.php
the console application configuration
console.php
控制台应用程序配置
web.php
the Web application configuration
web.php
Web 应用程序配置
commands/
contains console command classes
commands/
包含控制台命令类
controllers/
contains controller classes
controllers/
包含控制器类
models/
contains model classes
models/
包含模型类
runtime/
contains files generated by Yii during runtime, such as logs and cache files
runtime/
包含 Yii 运行时产生的文件,例如日志和缓存文件等
vendor/
contains the installed Composer packages, including the Yii framework itself
vendor/
包含已安装的 Componser 包,包括 Yii 框架本身。
views/
contains view files
views/
包含视图文件
web/
application Web root, contains Web accessible files
web/
应用程序 Web 根目录,包含可通过 Web 访问的文件
assets/
contains published asset files (javascript and css) by Yii
assets/
包含 Yii 已发布的资源文件(javascript 和 css)
index.php
the entry (or bootstrap) script for the application
index.php
应用程序的入口(或引导)脚本
yii
the Yii console command execution script
yii
Yii 控制台命令可执行脚本
```
```
In general, the files in the application can be divided into two types: those under
`basic/web`
and those
总体上,应用程序中的文件可以分为两类:位于
`basic/web`
中的和那些位于其他目录中的。前者可通过 HTTP (例如,在一个浏览器中)直接访问,
under other directories. The former can be directly accessed via HTTP (i.e., in a browser), while the latter can not and should not be.
后者则不能且不应该能。
Yii implements the
[
model-view-controller (MVC)
](
http://wikipedia.org/wiki/Model-view-controller
)
design pattern,
Yii 实现了
[
模型-视图-控制器 (MVC)
](
http://wikipedia.org/wiki/Model-view-controller
)
设计模式,在上述目录组织中也有体现。
which is reflected in the above directory organization. The
`models`
directory contains all
[
model classes
](
structure-models.md
)
,
`models`
目录中包含了所有的
[
模型类
](
structure-models.md
)
,
`views`
目录包含了所有的
[
视图脚本
](
structure-views.md
)
,
the
`views`
directory contains all
[
view scripts
](
structure-views.md
)
, and the
`controllers`
directory contains
`controllers`
目录包含了所有
[
控制器类
](
structure-controllers.md
)
。
all
[
controller classes
](
structure-controllers.md
)
.
The following diagram shows the static structure of an application.
下图展示了一个应用程序的静态结构。
![
Static Structure of Application
](
images/application-structure.png
)
![
应用程序的静态结构
](
images/application-structure.png
)
Each application has an entry script
`web/index.php`
which is the only Web accessible PHP script in the application.
每个应用程序都有一个入口脚本
`web/index.php`
,它是应用程序中仅有的可通过 Web 访问的 PHP 脚本。这个入口脚本接收一个传入请求并创建一个
The entry script takes an incoming request and creates an
[
application
](
structure-applications.md
)
instance to handle it.
[
应用程序
](
structure-applications.md
)
实例处理该请求。
[
应用程序
](
structure-applications.md
)
在其
[
组件
](
concept-components.md
)
The
[
application
](
structure-applications.md
)
resolves the request with the help of its
[
components
](
concept-components.md
)
,
的帮助下解析请求并将请求分派到 MVC 元素上。
[
视图
](
structure-views.md
)
中使用
[
挂件
](
structure-widgets.md
)
协助构建复杂动态的用户接口
and dispatches the request to the MVC elements.
[
Widgets
](
structure-widgets.md
)
are used in the
[
views
](
structure-views.md
)
元素。
to help build complex and dynamic user interface elements.
Request Lifecycle
<a name="request-lifecycle"></a>
请求的生命周期
<a name="request-lifecycle"></a>
-----------------
-----------------
The following diagram shows how an application handles a request.
下图展示了一个应用是如何处理请求的。
![
Request Lifecycle
](
images/application-lifecycle.png
)
![
请求的生命周期
](
images/application-lifecycle.png
)
1.
A user makes a request to the
[
entry script
](
structure-entry-scripts.md
)
`web/index.php`
.
1.
一个用户提交了对
[
入口脚本(entry script)
](
structure-entry-scripts.md
)
`web/index.php`
的请求。
2.
The entry script loads the application
[
configuration
](
concept-configurations.md
)
and creates
2.
入口脚本加载应用程序
[
配置信息(configuration)
](
concept-configurations.md
)
并创建一个
[
应用程序
](
structure-applications.md
)
实
an
[
application
](
structure-applications.md
)
instance to handle the request.
例处理该请求。
3.
The application resolves the requested
[
route
](
runtime-routing.md
)
with the help of
3.
应用程序在
[
请求(request)
]
应用程序组件的协助下解析所请求的
[
路由(route)
](
runtime-routing.md
)
。
the
[
request
](
runtime-requests.md
)
application component.
4.
应用程序创建一个
[
控制器(controller)
](
structure-controllers.md
)
实例处理该请求。
4.
The application creates a
[
controller
](
structure-controllers.md
)
instance to handle the request.
5.
控制器创建了一个
[
动作(action)
](
structure-controllers.md
)
实例,执行动作中的过滤器(filter)。
5.
The controller creates an
[
action
](
structure-controllers.md
)
instance and performs the filters for the action.
6.
如果有任何一个过滤器处理失败,则动作取消。
6.
If any filter fails, the action is cancelled.
7.
如果所有的过滤器都执行通过,则动作执行。
7.
If all filters pass, the action is executed.
8.
动作载入一个数据模型,可能是从一个数据库中加载。
8.
The action loads a data model, possibly from a database.
9.
动作渲染一个视图(view),给它提供数据模型。
9.
The action renders a view, providing it with the data model.
10.
渲染结果返回给
[
响应(response)
](
runtime-responses.md
)
应用程序组件。
10.
The rendered result is returned to the
[
response
](
runtime-responses.md
)
application component.
11.
响应组件发送渲染结果到用户的浏览器。
11.
The response component sends the rendered result to the user's browser.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment