1 | <?php |
||
22 | class Controller extends \yii\base\Controller |
||
23 | { |
||
24 | /** |
||
25 | * @var bool whether to enable CSRF validation for the actions in this controller. |
||
26 | * CSRF validation is enabled only when both this property and [[\yii\web\Request::enableCsrfValidation]] are true. |
||
27 | */ |
||
28 | public $enableCsrfValidation = true; |
||
29 | /** |
||
30 | * @var array the parameters bound to the current action. |
||
31 | */ |
||
32 | public $actionParams = []; |
||
33 | |||
34 | |||
35 | /** |
||
36 | * Renders a view in response to an AJAX request. |
||
37 | * |
||
38 | * This method is similar to [[renderPartial()]] except that it will inject into |
||
39 | * the rendering result with JS/CSS scripts and files which are registered with the view. |
||
40 | * For this reason, you should use this method instead of [[renderPartial()]] to render |
||
41 | * a view to respond to an AJAX request. |
||
42 | * |
||
43 | * @param string $view the view name. Please refer to [[render()]] on how to specify a view name. |
||
44 | * @param array $params the parameters (name-value pairs) that should be made available in the view. |
||
45 | * @return string the rendering result. |
||
46 | */ |
||
47 | public function renderAjax($view, $params = []) |
||
51 | |||
52 | /** |
||
53 | * Send data formatted as JSON. |
||
54 | * |
||
55 | * This method is a shortcut for sending data formatted as JSON. It will return |
||
56 | * the [[Application::getResponse()|response]] application component after configuring |
||
57 | * the [[Response::$format|format]] and setting the [[Response::$data|data]] that should |
||
58 | * be formatted. A common usage will be: |
||
59 | * |
||
60 | * ```php |
||
61 | * return $this->asJson($data); |
||
62 | * ``` |
||
63 | * |
||
64 | * @param mixed $data the data that should be formatted. |
||
65 | * @return Response a response that is configured to send `$data` formatted as JSON. |
||
66 | * @since 2.0.11 |
||
67 | * @see Response::$format |
||
68 | * @see Response::FORMAT_JSON |
||
69 | * @see JsonResponseFormatter |
||
70 | */ |
||
71 | 1 | public function asJson($data) |
|
78 | |||
79 | /** |
||
80 | * Send data formatted as XML. |
||
81 | * |
||
82 | * This method is a shortcut for sending data formatted as XML. It will return |
||
83 | * the [[Application::getResponse()|response]] application component after configuring |
||
84 | * the [[Response::$format|format]] and setting the [[Response::$data|data]] that should |
||
85 | * be formatted. A common usage will be: |
||
86 | * |
||
87 | * ```php |
||
88 | * return $this->asXml($data); |
||
89 | * ``` |
||
90 | * |
||
91 | * @param mixed $data the data that should be formatted. |
||
92 | * @return Response a response that is configured to send `$data` formatted as XML. |
||
93 | * @since 2.0.11 |
||
94 | * @see Response::$format |
||
95 | * @see Response::FORMAT_XML |
||
96 | * @see XmlResponseFormatter |
||
97 | */ |
||
98 | 1 | public function asXml($data) |
|
105 | |||
106 | /** |
||
107 | * Binds the parameters to the action. |
||
108 | * This method is invoked by [[\yii\base\Action]] when it begins to run with the given parameters. |
||
109 | * This method will check the parameter names that the action requires and return |
||
110 | * the provided parameters according to the requirement. If there is any missing parameter, |
||
111 | * an exception will be thrown. |
||
112 | * @param \yii\base\Action $action the action to be bound with parameters |
||
113 | * @param array $params the parameters to be bound to the action |
||
114 | * @return array the valid parameters that the action can run with. |
||
115 | * @throws BadRequestHttpException if there are missing or invalid parameters. |
||
116 | */ |
||
117 | 24 | public function bindActionParams($action, $params) |
|
158 | |||
159 | /** |
||
160 | * @inheritdoc |
||
161 | */ |
||
162 | 23 | public function beforeAction($action) |
|
173 | |||
174 | /** |
||
175 | * Redirects the browser to the specified URL. |
||
176 | * This method is a shortcut to [[Response::redirect()]]. |
||
177 | * |
||
178 | * You can use it in an action by returning the [[Response]] directly: |
||
179 | * |
||
180 | * ```php |
||
181 | * // stop executing this action and redirect to login page |
||
182 | * return $this->redirect(['login']); |
||
183 | * ``` |
||
184 | * |
||
185 | * @param string|array $url the URL to be redirected to. This can be in one of the following formats: |
||
186 | * |
||
187 | * - a string representing a URL (e.g. "http://example.com") |
||
188 | * - a string representing a URL alias (e.g. "@example.com") |
||
189 | * - an array in the format of `[$route, ...name-value pairs...]` (e.g. `['site/index', 'ref' => 1]`) |
||
190 | * [[Url::to()]] will be used to convert the array into a URL. |
||
191 | * |
||
192 | * Any relative URL will be converted into an absolute one by prepending it with the host info |
||
193 | * of the current request. |
||
194 | * |
||
195 | * @param int $statusCode the HTTP status code. Defaults to 302. |
||
196 | * See <http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html> |
||
197 | * for details about HTTP status code |
||
198 | * @return Response the current response object |
||
199 | */ |
||
200 | public function redirect($url, $statusCode = 302) |
||
204 | |||
205 | /** |
||
206 | * Redirects the browser to the home page. |
||
207 | * |
||
208 | * You can use this method in an action by returning the [[Response]] directly: |
||
209 | * |
||
210 | * ```php |
||
211 | * // stop executing this action and redirect to home page |
||
212 | * return $this->goHome(); |
||
213 | * ``` |
||
214 | * |
||
215 | * @return Response the current response object |
||
216 | */ |
||
217 | public function goHome() |
||
221 | |||
222 | /** |
||
223 | * Redirects the browser to the last visited page. |
||
224 | * |
||
225 | * You can use this method in an action by returning the [[Response]] directly: |
||
226 | * |
||
227 | * ```php |
||
228 | * // stop executing this action and redirect to last visited page |
||
229 | * return $this->goBack(); |
||
230 | * ``` |
||
231 | * |
||
232 | * For this function to work you have to [[User::setReturnUrl()|set the return URL]] in appropriate places before. |
||
233 | * |
||
234 | * @param string|array $defaultUrl the default return URL in case it was not set previously. |
||
235 | * If this is null and the return URL was not set previously, [[Application::homeUrl]] will be redirected to. |
||
236 | * Please refer to [[User::setReturnUrl()]] on accepted format of the URL. |
||
237 | * @return Response the current response object |
||
238 | * @see User::getReturnUrl() |
||
239 | */ |
||
240 | public function goBack($defaultUrl = null) |
||
244 | |||
245 | /** |
||
246 | * Refreshes the current page. |
||
247 | * This method is a shortcut to [[Response::refresh()]]. |
||
248 | * |
||
249 | * You can use it in an action by returning the [[Response]] directly: |
||
250 | * |
||
251 | * ```php |
||
252 | * // stop executing this action and refresh the current page |
||
253 | * return $this->refresh(); |
||
254 | * ``` |
||
255 | * |
||
256 | * @param string $anchor the anchor that should be appended to the redirection URL. |
||
257 | * Defaults to empty. Make sure the anchor starts with '#' if you want to specify it. |
||
258 | * @return Response the response object itself |
||
259 | */ |
||
260 | public function refresh($anchor = '') |
||
264 | } |
||
265 |
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: