From b079c73a9403baf8cc887b8aebe67665b15c70fb Mon Sep 17 00:00:00 2001 From: Mark Date: Sun, 29 Dec 2013 22:08:01 +0400 Subject: [PATCH 1/3] docs about response --- docs/guide/controller.md | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/docs/guide/controller.md b/docs/guide/controller.md index 682d1f7..8e1227e 100644 --- a/docs/guide/controller.md +++ b/docs/guide/controller.md @@ -35,7 +35,29 @@ class SiteController extends Controller ``` As you can see, typical controller contains actions that are public class methods named as `actionSomething`. -The output of an action is what the method returns. The return value will be handled by the `response` application +The output of an action is what the method returns, it could be rendered result or it can be instance of ```yii\web\Response```, for example: + +```php +namespace app\controllers; + +use yii\web\Controller; +use app\components\web\MyCustomResponse; #extended from yii\web\Response + +class SiteController extends Controller +{ + public function actionCustom() + { + /* + * do your things here + * since Response in extended from yii\base\Object, you can initialize its values by passing in + * __constructor() simple array. + */ + return new MyCustomResponse(['data' => $myCustomData]); + } +} +``` + +The return value will be handled by the `response` application component which can convert the output to differnet formats such as JSON for example. The default behavior is to output the value unchanged though. From 2081c6f40d3f9b756c604a9c68342f0dec4a01e2 Mon Sep 17 00:00:00 2001 From: Mark Date: Sun, 29 Dec 2013 22:38:39 +0400 Subject: [PATCH 2/3] subsection added --- docs/guide/controller.md | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/docs/guide/controller.md b/docs/guide/controller.md index 8e1227e..4b088f4 100644 --- a/docs/guide/controller.md +++ b/docs/guide/controller.md @@ -35,28 +35,7 @@ class SiteController extends Controller ``` As you can see, typical controller contains actions that are public class methods named as `actionSomething`. -The output of an action is what the method returns, it could be rendered result or it can be instance of ```yii\web\Response```, for example: - -```php -namespace app\controllers; - -use yii\web\Controller; -use app\components\web\MyCustomResponse; #extended from yii\web\Response - -class SiteController extends Controller -{ - public function actionCustom() - { - /* - * do your things here - * since Response in extended from yii\base\Object, you can initialize its values by passing in - * __constructor() simple array. - */ - return new MyCustomResponse(['data' => $myCustomData]); - } -} -``` - +The output of an action is what the method returns, it could be rendered result or it can be instance of ```yii\web\Response```, for [example](#custom-response-class). The return value will be handled by the `response` application component which can convert the output to differnet formats such as JSON for example. The default behavior is to output the value unchanged though. @@ -271,4 +250,27 @@ TBD See also -------- +Custom response class +--------------------- + +```php +namespace app\controllers; + +use yii\web\Controller; +use app\components\web\MyCustomResponse; #extended from yii\web\Response + +class SiteController extends Controller +{ + public function actionCustom() + { + /* + * do your things here + * since Response in extended from yii\base\Object, you can initialize its values by passing in + * __constructor() simple array. + */ + return new MyCustomResponse(['data' => $myCustomData]); + } +} +``` + - [Console](console.md) From cf917bee7897d029b53c96a3153122965d483251 Mon Sep 17 00:00:00 2001 From: Mark Date: Sun, 29 Dec 2013 22:41:02 +0400 Subject: [PATCH 3/3] moved section --- docs/guide/controller.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/guide/controller.md b/docs/guide/controller.md index 4b088f4..193fe37 100644 --- a/docs/guide/controller.md +++ b/docs/guide/controller.md @@ -247,9 +247,6 @@ Catching all incoming requests TBD -See also --------- - Custom response class --------------------- @@ -273,4 +270,7 @@ class SiteController extends Controller } ``` +See also +-------- + - [Console](console.md)