PHP Класс yii\web\Controller

С версии: 2.0
Автор: Qiang Xue ([email protected])
Наследование: extends yii\base\Controller
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$actionParams the parameters bound to the current action.
$enableCsrfValidation whether to enable CSRF validation for the actions in this controller. CSRF validation is enabled only when both this property and [[\yii\web\Request::enableCsrfValidation]] are true.

Открытые методы

Метод Описание
asJson ( mixed $data ) : Response Send data formatted as JSON.
asXml ( mixed $data ) : Response Send data formatted as XML.
beforeAction ( $action )
bindActionParams ( Action $action, array $params ) : array Binds the parameters to the action.
goBack ( string | array $defaultUrl = null ) : Response Redirects the browser to the last visited page.
goHome ( ) : Response Redirects the browser to the home page.
redirect ( string | array $url, integer $statusCode = 302 ) : Response Redirects the browser to the specified URL.
refresh ( string $anchor = '' ) : Response Refreshes the current page.
renderAjax ( string $view, array $params = [] ) : string Renders a view in response to an AJAX request.

Описание методов

asJson() публичный метод

This method is a shortcut for sending data formatted as JSON. It will return the [[Application::getResponse()|response]] application component after configuring the [[Response::$format|format]] and setting the [[Response::$data|data]] that should be formatted. A common usage will be: php return $this->asJson($data);
См. также: Response::$format
См. также: Response::FORMAT_JSON
См. также: JsonResponseFormatter
С версии: 2.0.11
public asJson ( mixed $data ) : Response
$data mixed the data that should be formatted.
Результат Response a response that is configured to send `$data` formatted as JSON.

asXml() публичный метод

This method is a shortcut for sending data formatted as XML. It will return the [[Application::getResponse()|response]] application component after configuring the [[Response::$format|format]] and setting the [[Response::$data|data]] that should be formatted. A common usage will be: php return $this->asXml($data);
См. также: Response::$format
См. также: Response::FORMAT_XML
См. также: XmlResponseFormatter
С версии: 2.0.11
public asXml ( mixed $data ) : Response
$data mixed the data that should be formatted.
Результат Response a response that is configured to send `$data` formatted as XML.

beforeAction() публичный метод

public beforeAction ( $action )

bindActionParams() публичный метод

This method is invoked by Action when it begins to run with the given parameters. This method will check the parameter names that the action requires and return the provided parameters according to the requirement. If there is any missing parameter, an exception will be thrown.
public bindActionParams ( Action $action, array $params ) : array
$action yii\base\Action the action to be bound with parameters
$params array the parameters to be bound to the action
Результат array the valid parameters that the action can run with.

goBack() публичный метод

You can use this method in an action by returning the Response directly: php stop executing this action and redirect to last visited page return $this->goBack(); For this function to work you have to [[User::setReturnUrl()|set the return URL]] in appropriate places before.
См. также: User::getReturnUrl()
public goBack ( string | array $defaultUrl = null ) : Response
$defaultUrl string | array the default return URL in case it was not set previously. If this is null and the return URL was not set previously, [[Application::homeUrl]] will be redirected to. Please refer to [[User::setReturnUrl()]] on accepted format of the URL.
Результат Response the current response object

goHome() публичный метод

You can use this method in an action by returning the Response directly: php stop executing this action and redirect to home page return $this->goHome();
public goHome ( ) : Response
Результат Response the current response object

redirect() публичный метод

This method is a shortcut to [[Response::redirect()]]. You can use it in an action by returning the Response directly: php stop executing this action and redirect to login page return $this->redirect(['login']);
public redirect ( string | array $url, integer $statusCode = 302 ) : Response
$url string | array the URL to be redirected to. This can be in one of the following formats: - a string representing a URL (e.g. "http://example.com") - a string representing a URL alias (e.g. "@example.com") - an array in the format of `[$route, ...name-value pairs...]` (e.g. `['site/index', 'ref' => 1]`) [[Url::to()]] will be used to convert the array into a URL. Any relative URL will be converted into an absolute one by prepending it with the host info of the current request.
$statusCode integer the HTTP status code. Defaults to 302. See for details about HTTP status code
Результат Response the current response object

refresh() публичный метод

This method is a shortcut to [[Response::refresh()]]. You can use it in an action by returning the Response directly: php stop executing this action and refresh the current page return $this->refresh();
public refresh ( string $anchor = '' ) : Response
$anchor string the anchor that should be appended to the redirection URL. Defaults to empty. Make sure the anchor starts with '#' if you want to specify it.
Результат Response the response object itself

renderAjax() публичный метод

This method is similar to [[renderPartial()]] except that it will inject into the rendering result with JS/CSS scripts and files which are registered with the view. For this reason, you should use this method instead of [[renderPartial()]] to render a view to respond to an AJAX request.
public renderAjax ( string $view, array $params = [] ) : string
$view string the view name. Please refer to [[render()]] on how to specify a view name.
$params array the parameters (name-value pairs) that should be made available in the view.
Результат string the rendering result.

Описание свойств

$actionParams публичное свойство

the parameters bound to the current action.
public $actionParams

$enableCsrfValidation публичное свойство

whether to enable CSRF validation for the actions in this controller. CSRF validation is enabled only when both this property and [[\yii\web\Request::enableCsrfValidation]] are true.
public $enableCsrfValidation