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
84d37cff
Commit
84d37cff
authored
Sep 28, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added bootstapping tutorial
parent
61b4180f
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
1 deletion
+69
-1
README.md
docs/guide/README.md
+2
-1
runtime-bootstrapping.md
docs/guide/runtime-bootstrapping.md
+43
-0
runtime-overview.md
docs/guide/runtime-overview.md
+24
-0
No files found.
docs/guide/README.md
View file @
84d37cff
...
...
@@ -47,7 +47,8 @@ Application Structure
Handling Requests
-----------------
*
**TBD**
[
Bootstrapping
](
runtime-bootstrapping.md
)
*
[
Overview
](
runtime-overview.md
)
*
[
Bootstrapping
](
runtime-bootstrapping.md
)
*
**TBD**
[
Routing
](
runtime-routing.md
)
*
**TBD**
[
Requests
](
runtime-requests.md
)
*
**TBD**
[
Responses
](
runtime-responses.md
)
...
...
docs/guide/runtime-bootstrapping.md
View file @
84d37cff
Bootstrapping
=============
Bootstrapping refers to the process of preparing the environment before an application starts
to resolve and process an incoming request. Bootstrapping is done in two places:
the
[
entry script
](
structure-entry-scripts.md
)
and the
[
application
](
structure-applications.md
)
.
In the
[
entry script
](
structure-entry-scripts.md
)
, class autoloaders for different libraries are
registered. This includes the Composer autoloader through its
`autoload.php`
file and the Yii
autoloader through its
`Yii`
class file. The entry script then loads the application
[
configuration
](
concept-configurations.md
)
and creates an
[
application
](
structure-applications.md
)
instance.
In the constructor of the application, the following bootstrapping work are done:
1.
[
[yii\base\Application::preInit()|preInit()
]
] is called, which configures some high priority
application properties, such as
[
[yii\base\Application::basePath|basePath
]
].
2.
Register the
[
[yii\base\Application::errorHandler|error handler
]
].
3.
Initialize application properties using the given application configuration.
4.
[
[yii\base\Application::init()|init()
]
] is called which in turn calls
[
[yii\base\Application::bootstrap()|bootstrap()
]
] to run bootstrapping components.
-
Include the extension manifest file
`vendor/yiisoft/extensions.php`
.
-
Create and run
[
bootstrap components
](
structure-extensions.md#bootstrapping-classes
)
declared by extensions.
-
Create and run
[
application components
](
structure-application-components.md
)
and/or
[
modules
](
structure-modules.md
)
that are declared in the application's
[
bootstrap property
](
structure-applications.md#bootstrap
)
.
Because the bootstrapping work has to be done before handling
*every*
request, it is very important
to keep this process light and optimize it as much as possible.
Try not to register too many bootstrapping components. A bootstrapping component is needed only
if it wants to participate the whole life cycle of requesting handling. For example, if a module
needs to register additional URL parsing rules, it should be listed in the
[
bootstrap property
](
structure-applications.md#bootstrap
)
so that the new URL rules can take effect
before they are used to resolve requests.
In production mode, enable bytecode cache, such as APC, to minimize the time needed for including
and parsing PHP files.
Some large applications have very complex application
[
configurations
](
concept-configurations.md
)
which are divided into many smaller configuration files. If this is the case, consider caching
the whole configuration array and loading it directly from cache before creating the application instance
in the entry script.
docs/guide/runtime-overview.md
View file @
84d37cff
Overview
========
Each time when a Yii application handles a request, it undergoes a similar workflow.
1.
A user makes a request to the
[
entry script
](
structure-entry-scripts.md
)
`web/index.php`
.
2.
The entry script loads the application
[
configuration
](
concept-configurations.md
)
and creates
an
[
application
](
structure-applications.md
)
instance to handle the request.
3.
The application resolves the requested
[
route
](
runtime-routing.md
)
with the help of
the
[
request
](
runtime-requests.md
)
application component.
4.
The application creates a
[
controller
](
structure-controllers.md
)
instance to handle the request.
5.
The controller creates an
[
action
](
structure-controllers.md
)
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
](
runtime-responses.md
)
application component.
11.
The response component sends the rendered result to the user's browser.
The following diagram shows how an application handles a request.
![
Request Lifecycle
](
images/application-lifecycle.png
)
In this section, we will describe in detail how some of these steps work.
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