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
0de53fe0
Commit
0de53fe0
authored
May 27, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
guide WIP [skip ci]
parent
6314135e
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
87 additions
and
2 deletions
+87
-2
structure-applications.md
docs/guide/structure-applications.md
+87
-2
No files found.
docs/guide/structure-applications.md
View file @
0de53fe0
...
@@ -48,11 +48,16 @@ where to store temporary files, etc. In the following, we will summarize these p
...
@@ -48,11 +48,16 @@ where to store temporary files, etc. In the following, we will summarize these p
In any application, you should at least configure two properties:
[
[yii\base\Application::id|id
]
]
In any application, you should at least configure two properties:
[
[yii\base\Application::id|id
]
]
and
[
[yii\base\Application::basePath|basePath
]
].
and
[
[yii\base\Application::basePath|basePath
]
].
####
#### [[yii\base\Application::id|id]]
The
[
[yii\base\Application::id|id
]
] property specifies a unique ID that differentiates an application
The
[
[yii\base\Application::id|id
]
] property specifies a unique ID that differentiates an application
from others. It is mainly used programmatically. Although not a requirement, for best interoperability
from others. It is mainly used programmatically. Although not a requirement, for best interoperability
it is recommended that you use alphanumeric characters only when specifying an application ID.
it is recommended that you use alphanumeric characters only when specifying an application ID.
#### [[yii\base\Application::basePath|basePath]]
The
[
[yii\base\Application::basePath|basePath
]
] property specifies the root directory of an application.
The
[
[yii\base\Application::basePath|basePath
]
] property specifies the root directory of an application.
It is the directory that contains all protected source code of an application system. Under this directory,
It is the directory that contains all protected source code of an application system. Under this directory,
you normally will see sub-directories such as
`models`
,
`views`
,
`controllers`
, which contain source code
you normally will see sub-directories such as
`models`
,
`views`
,
`controllers`
, which contain source code
...
@@ -69,7 +74,8 @@ path. Derived paths may then be formed using this alias (e.g. `@app/runtime` to
...
@@ -69,7 +74,8 @@ path. Derived paths may then be formed using this alias (e.g. `@app/runtime` to
### Important Properties
### Important Properties
You usually will configure the properties as their values differ across different applications.
The properties described in this subsection often need to be configured because they differ across
different applications.
#### [[yii\base\Application::aliases|aliases]]
#### [[yii\base\Application::aliases|aliases]]
...
@@ -129,13 +135,92 @@ During the bootstrapping process, each component will be instantiated. If the co
...
@@ -129,13 +135,92 @@ During the bootstrapping process, each component will be instantiated. If the co
implements
[
[yii\base\BootstrapInterface
]
], its
[
[yii\base\BootstrapInterface::bootstrap()|bootstrap()
]
] method
implements
[
[yii\base\BootstrapInterface
]
], its
[
[yii\base\BootstrapInterface::bootstrap()|bootstrap()
]
] method
will be also be called.
will be also be called.
Another practical example is in the application configuration for the
[
Basic Application Template
](
start-installation.md
)
,
where the
`debug`
and
`gii`
modules are configured as bootstrap components when the application is running
in development environment,
```
php
if
(
YII_ENV_DEV
)
{
// configuration adjustments for 'dev' environment
$config
[
'bootstrap'
][]
=
'debug'
;
$config
[
'modules'
][
'debug'
]
=
'yii\debug\Module'
;
$config
[
'bootstrap'
][]
=
'gii'
;
$config
[
'modules'
][
'gii'
]
=
'yii\gii\Module'
;
}
```
> Note: Putting too many components in `bootstrap` will degrade the performance of your application because
for each request, the same set of components need to be run. So use bootstrap components judiciously.
#### [[yii\base\Application::components|components]]
#### [[yii\base\Application::components|components]]
This is the single most important property. It allows you to configure a list of named components
called
*application components*
that you can use in other places. For example,
```
php
[
'components'
=>
[
'cache'
=>
[
'class'
=>
'yii\caching\FileCache'
,
],
'user'
=>
[
'identityClass'
=>
'app\models\User'
,
'enableAutoLogin'
=>
true
,
],
],
]
```
More details about how to configure and use this property are described in the
[
application components
](
#application-components
)
section.
#### [[yii\base\Application::controllerMap|controllerMap]]
#### [[yii\base\Application::controllerMap|controllerMap]]
This property allows you to map a controller ID to an arbitrary controller class. By default, Yii maps
controller IDs to controller classes based on a
[
convention
](
#controllerNamespace
)
(
e.g.
the ID
`post`
would be mapped
to
`app\controllers\PostController`
). By configuring this property, you can break the convention for
specific controllers. In the following example,
`account`
will be mapped to
`app\controllers\UserController`
, while
`article`
will be mapped to
`app\controllers\PostController`
.
```
php
[
'controllerMap'
=>
[
[
'account'
=>
'app\controllers\UserController'
,
'article'
=>
[
'class'
=>
'app\controllers\PostController'
,
'pageTitle'
=>
'something new'
,
],
],
],
]
```
The array keys of this property represent the controller IDs, while the array values represent the corresponding
controller class names or
[
configurations
](
concept-configurations.md
)
.
#### [[yii\base\Application::controllerNamespace|controllerNamespace]]
#### [[yii\base\Application::controllerNamespace|controllerNamespace]]
This property specifies the default namespace under which controller classes should be located. It defaults to
`app\controllers`
. If a controller ID is
`post`
, by convention the corresponding controller class name (without
namespace) would be
`PostController`
, and the fully qualified class name would be
`app\controllers\PostController`
.
Controller classes may also be located under sub-directories of the directory corresponding to this namespace.
For example, given a controller ID
`admin/post`
, the corresponding fully qualified controller class would
be
`app\controllers\admin\PostController`
.
It is important that the fully qualified controller classes should be
[
autoloadable
](
concept-autoloading.md
)
and the actual namespace of your controller classes match the value of this property. Otherwise,
you will receive "Page Not Found" error when accessing the application.
In case you want to break the convention as described above, you may configure the
[
controllerMap
](
#controllerMap
)
property.
#### [[yii\base\Application::language|language]]
#### [[yii\base\Application::language|language]]
#### [[yii\base\Application::modules|modules]]
#### [[yii\base\Application::modules|modules]]
...
...
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