Commit 60b38a1a by Qiang Xue

Finished filter section [skip ci]

parent 02e37460
...@@ -136,8 +136,20 @@ $component->attachBehaviors([ ...@@ -136,8 +136,20 @@ $component->attachBehaviors([
]); ]);
``` ```
You may also attach behaviors through [configurations](concept-configurations.md). For more details, please You may also attach behaviors through [configurations](concept-configurations.md) like the following. For more details,
refer to the [Configurations](concept-configurations.md#configuration-format) section. please refer to the [Configurations](concept-configurations.md#configuration-format) section.
```php
[
'as myBehavior2' => MyBehavior::className(),
'as myBehavior3' => [
'class' => MyBehavior::className(),
'prop1' => 'value1',
'prop2' => 'value2',
],
]
```
Detaching Behaviors <a name="detaching-behaviors"></a> Detaching Behaviors <a name="detaching-behaviors"></a>
......
...@@ -162,6 +162,18 @@ $foo->on(Foo::EVENT_HELLO, function ($event) { ...@@ -162,6 +162,18 @@ $foo->on(Foo::EVENT_HELLO, function ($event) {
}, $data, false); }, $data, false);
``` ```
Besides calling the `on()` method, you may also attach event handlers in [configurations](concept-configurations.md)
like the following. For more details, please refer to the [Configurations](concept-configurations.md#configuration-format)
section.
```php
[
'on hello' => function ($event) {
echo 'hello event is triggered';
}
]
```
Detaching Event Handlers <a name="detaching-event-handlers"></a> Detaching Event Handlers <a name="detaching-event-handlers"></a>
------------------------ ------------------------
......
...@@ -2,10 +2,13 @@ Controllers ...@@ -2,10 +2,13 @@ Controllers
=========== ===========
Controllers are part of the [MVC](http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller) architecture. Controllers are part of the [MVC](http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller) architecture.
They are objects responsible for processing requests and generating responses. In particular, after They are objects of classes extending from [[yii\base\Controller]] and are responsible for processing requests and
taking over the control from [applications](structure-applications.md), controllers will analyze incoming request data, generating responses. In particular, after taking over the control from [applications](structure-applications.md),
pass them to [models](structure-models.md), inject model results into [views](structure-views.md), controllers will analyze incoming request data, pass them to [models](structure-models.md), inject model results
and finally generate outgoing responses. into [views](structure-views.md), and finally generate outgoing responses.
## Actions <a name="actions"></a>
Controllers are composed by *actions* which are the most basic units that end users can address and request for Controllers are composed by *actions* which are the most basic units that end users can address and request for
execution. A controller can have one or multiple actions. execution. A controller can have one or multiple actions.
......
...@@ -21,7 +21,7 @@ structure-controllers.md | Yes ...@@ -21,7 +21,7 @@ structure-controllers.md | Yes
structure-views.md | Yes structure-views.md | Yes
structure-models.md | Yes structure-models.md | Yes
structure-modules.md | Yes structure-modules.md | Yes
structure-filters.md | structure-filters.md | Yes
structure-widgets.md | structure-widgets.md |
structure-assets.md | structure-assets.md |
structure-extensions.md | structure-extensions.md |
......
...@@ -12,11 +12,11 @@ use yii\base\ActionFilter; ...@@ -12,11 +12,11 @@ use yii\base\ActionFilter;
use yii\base\Action; use yii\base\Action;
/** /**
* The HttpCache provides functionality for caching via HTTP Last-Modified and Etag headers. * HttpCache implements client-side caching by utilizing the `Last-Modified` and `Etag` HTTP headers.
* *
* It is an action filter that can be added to a controller and handles the `beforeAction` event. * It is an action filter that can be added to a controller and handles the `beforeAction` event.
* *
* To use AccessControl, declare it in the `behaviors()` method of your controller class. * To use HttpCache, declare it in the `behaviors()` method of your controller class.
* In the following example the filter will be applied to the `list`-action and * In the following example the filter will be applied to the `list`-action and
* the Last-Modified header will contain the date of the last update to the user table in the database. * the Last-Modified header will contain the date of the last update to the user table in the database.
* *
...@@ -24,7 +24,7 @@ use yii\base\Action; ...@@ -24,7 +24,7 @@ use yii\base\Action;
* public function behaviors() * public function behaviors()
* { * {
* return [ * return [
* 'httpCache' => [ * [
* 'class' => 'yii\filters\HttpCache', * 'class' => 'yii\filters\HttpCache',
* 'only' => ['index'], * 'only' => ['index'],
* 'lastModified' => function ($action, $params) { * 'lastModified' => function ($action, $params) {
......
...@@ -13,15 +13,14 @@ use yii\base\Action; ...@@ -13,15 +13,14 @@ use yii\base\Action;
use yii\caching\Dependency; use yii\caching\Dependency;
/** /**
* The PageCache provides functionality for whole page caching * PageCache implements server-side caching of whole pages.
* *
* It is an action filter that can be added to a controller and handles the `beforeAction` event. * It is an action filter that can be added to a controller and handles the `beforeAction` event.
* *
* To use PageCache, declare it in the `behaviors()` method of your controller class. * To use PageCache, declare it in the `behaviors()` method of your controller class.
* In the following example the filter will be applied to the `list`-action and * In the following example the filter will be applied to the `index` action and
* cache the whole page for maximum 60 seconds or until the count of entries in the post table changes. * cache the whole page for maximum 60 seconds or until the count of entries in the post table changes.
* It also stores different versions of the page depended on the route ([[varyByRoute]] is true by default), * It also stores different versions of the page depending on the application language.
* the application language and user id.
* *
* ~~~ * ~~~
* public function behaviors() * public function behaviors()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment