PHP 클래스 yii\web\Controller

부터: 2.0
저자: Qiang Xue ([email protected])
상속: extends yii\base\Controller
파일 보기 프로젝트 열기: yiisoft/yii2 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$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