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
768f94f9
Commit
768f94f9
authored
Jun 17, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finished module guide [skip ci]
parent
ffa596f5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
2 deletions
+28
-2
structure-application-components.md
docs/guide/structure-application-components.md
+27
-1
structure-modules.md
docs/guide/structure-modules.md
+0
-0
structure-views.md
docs/guide/structure-views.md
+1
-1
No files found.
docs/guide/structure-application-components.md
View file @
768f94f9
...
...
@@ -10,12 +10,15 @@ Each application component has an ID that uniquely identifies itself among other
in the same application. You can access an application component through the expression
```
php
\Yii
::
$app
->
C
omponentID
\Yii
::
$app
->
c
omponentID
```
For example, you can use
`\Yii::$app->db`
to get the
[
[yii\db\Connection|DB connection
]
],
and
`\Yii::$app->cache`
to get the
[
[yii\caching\Cache|primary cache
]
] registered with the application.
An application component is created the first time it is accessed through the above expression. Any
further accesses will return the same component instance.
Application components can be any objects. You can register them by configuring
the
[
[yii\base\Application::components
]
] property in
[
application configurations
](
structure-applications.md#application-configurations
)
.
For example,
...
...
@@ -48,6 +51,29 @@ For example,
and use it when needed.
## Bootstrapping Components <a name="bootstrapping-components"></a>
As mentioned above, an application component will only be instantiated when it is being accessed the first time.
If it is not accessed at all during a request, it will not be instantiated. Sometimes, however, you may want
to instantiate an application component for every request, even if it is not explicitly accessed.
To do so, you may list its ID in the
[
[yii\base\Application::bootstrap|bootstrap
]
] property of the application.
For example, the following application configuration makes sure the
`log`
component is always loaded:
```
php
[
'bootstrap'
=>
[
'log'
,
],
'components'
=>
[
'log'
=>
[
// configuration for "log" component
],
],
]
```
## Core Application Components <a name="core-application-components"></a>
Yii defines a set of
*core*
application components with fixed IDs and default configurations. For example,
...
...
docs/guide/structure-modules.md
View file @
768f94f9
This diff is collapsed.
Click to expand it.
docs/guide/structure-views.md
View file @
768f94f9
...
...
@@ -89,7 +89,7 @@ use yii\helpers\HtmlPurifier;
Like
[
controllers
](
structure-controllers.md
)
and
[
models
](
structure-models.md
)
, there are conventions to organize views.
*
For views rendered
in
a controller, they should be put under the directory
`@app/views/ControllerID`
by default,
*
For views rendered
by
a controller, they should be put under the directory
`@app/views/ControllerID`
by default,
where
`ControllerID`
refers to the
[
controller ID
](
structure-controllers.md#routes
)
. For example, if
the controller class is
`PostController`
, the directory would be
`@app/views/post`
; If it is
`PostCommentController`
,
the directory would be
`@app/views/post-comment`
. In case the controller belongs to a module, the directory
...
...
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