PHP 클래스 Cake\Controller\Controller

Provides basic functionality, such as rendering views inside layouts, automatic model availability, redirection, callbacks, and more. Controllers should provide a number of 'action' methods. These are public methods on a controller that are not inherited from Controller. Each action serves as an endpoint for performing a specific action on a resource or collection of resources. For example adding or editing a new object, or listing a set of objects. You can access request parameters, using $this->request. The request object contains all the POST, GET and FILES that were part of the request. After performing the required action, controllers are responsible for creating a response. This usually takes the form of a generated View, or possibly a redirection to another URL. In either case $this->response allows you to manipulate all aspects of the response. Controllers are created by Dispatcher based on request parameters and routing. By default controllers and actions use conventional names. For example /posts/index maps to PostsController::index(). You can re-map URLs using Router::connect() or RouterBuilder::connect(). ### Life cycle callbacks CakePHP fires a number of life cycle callbacks during each request. By implementing a method you can receive the related events. The available callbacks are: - beforeFilter(Event $event) Called before each action. This is a good place to do general logic that applies to all actions. - beforeRender(Event $event) Called before the view is rendered. - beforeRedirect(Event $event, $url, Response $response) Called before a redirect is done. - afterFilter(Event $event) Called after each action is complete and after the view is rendered.
상속: implements Cake\Event\EventListenerInterface, implements Cake\Event\EventDispatcherInterface, use trait Cake\Event\EventDispatcherTrait, use trait Cake\ORM\Locator\LocatorAwareTrait, use trait Cake\Log\LogTrait, use trait Cake\Utility\MergeVariablesTrait, use trait Cake\Datasource\ModelAwareTrait, use trait Cake\Routing\RequestActionTrait, use trait Cake\View\ViewVarsTrait
파일 보기 프로젝트 열기: cakephp/cakephp 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$View Cake\View\View Instance of the View created during rendering. Won't be set until after Controller::render() is called.
$autoRender boolean Set to true to automatically render the view after action logic.
$components array Example: public $components = ['RequestHandler', 'Acl'];
$helpers array Example: public $helpers = ['Form', 'Html', 'Time'];
$name string Set automatically using conventions in Controller::__construct().
$paginate array Used to pre-configure pagination preferences for the various tables your controller will be paginating.
$passedArgs array Holds all passed params.
$plugin string Automatically set to the name of a plugin.
$request Cake\Network\Request This object contains all the information about a request and several methods for reading additional information about the request.
$response Cake\Network\Response An instance of a Response object that contains information about the impending response

보호된 프로퍼티들

프로퍼티 타입 설명
$_components Cake\Controller\ComponentRegistry Instance of ComponentRegistry used to create Components
$_responseClass string The class name to use for creating the response object.
$_validViewOptions array These Controller properties will be passed from the Controller to the View as options.

공개 메소드들

메소드 설명
__construct ( Cake\Network\Request $request = null, Response $response = null, string | null $name = null, Cake\Event\EventManager | null $eventManager = null, Cake\Controller\ComponentRegistry | null $components = null ) Constructor.
__get ( string $name ) : boolean | object Magic accessor for model autoloading.
__set ( string $name, mixed $value ) : void Magic setter for removed properties.
afterFilter ( Cake\Event\Event $event ) : Response | null Called after the controller action is run and rendered.
beforeFilter ( Cake\Event\Event $event ) : Response | null Called before the controller action. You can use this method to configure and customize components or perform logic that needs to happen before each controller action.
beforeRedirect ( Cake\Event\Event $event, string | array $url, Response $response ) : Response | null The beforeRedirect method is invoked when the controller's redirect method is called but before any further action.
beforeRender ( Cake\Event\Event $event ) : Response | null Called after the controller action is run, but before the view is rendered. You can use this method to perform logic or set view variables that are required on every request.
components ( Cake\Controller\ComponentRegistry | null $components = null ) : Cake\Controller\ComponentRegistry Get the component registry for this controller.
implementedEvents ( ) : array Returns a list of all events that will fire in the controller during its lifecycle.
initialize ( ) : void Initialization hook method.
invokeAction ( ) : mixed Dispatches the controller action. Checks that the action exists and isn't private.
isAction ( string $action ) : boolean Method to check that an action is accessible from a URL.
loadComponent ( string $name, array $config = [] ) : Component Add a component to the controller's registry.
paginate ( Table | string | Query | null $object = null, array $settings = [] ) : Cake\ORM\ResultSet Handles pagination of records in Table objects.
redirect ( string | array $url, integer $status = 302 ) : Response | null Redirects to given $url, after turning off $this->autoRender.
referer ( string | array | null $default = null, boolean $local = false ) : string Returns the referring URL for this request.
render ( string | null $view = null, string | null $layout = null ) : Response Instantiates the correct view class, hands it its data, and uses it to render the view output.
setAction ( string $action ) : mixed Internally redirects one action to another. Does not perform another HTTP request unlike Controller::redirect()
setRequest ( Cake\Network\Request $request ) : void Sets the request objects and configures a number of controller properties based on the contents of the request. Controller acts as a proxy for certain View variables which must also be updated here. The properties that get set are:
shutdownProcess ( ) : Response | null Perform the various shutdown processes for this controller.
startupProcess ( ) : Response | null Perform the startup process for this controller.

보호된 메소드들

메소드 설명
_loadComponents ( ) : void Loads the defined components using the Component factory.
_mergeControllerVars ( ) : void Merge components, helpers vars from parent classes.
_viewPath ( ) : string Get the viewPath based on controller name and request prefix.

메소드 상세

__construct() 공개 메소드

Sets a number of properties based on conventions if they are empty. To override the conventions CakePHP uses you can define properties in your class declaration.
public __construct ( Cake\Network\Request $request = null, Response $response = null, string | null $name = null, Cake\Event\EventManager | null $eventManager = null, Cake\Controller\ComponentRegistry | null $components = null )
$request Cake\Network\Request Request object for this controller. Can be null for testing, but expect that features that use the request parameters will not work.
$response Cake\Network\Response Response object for this controller.
$name string | null Override the name useful in testing when using mocks.
$eventManager Cake\Event\EventManager | null The event manager. Defaults to a new instance.
$components Cake\Controller\ComponentRegistry | null The component registry. Defaults to a new instance.

__get() 공개 메소드

Magic accessor for model autoloading.
public __get ( string $name ) : boolean | object
$name string Property name
리턴 boolean | object The model instance or false

__set() 공개 메소드

Magic setter for removed properties.
public __set ( string $name, mixed $value ) : void
$name string Property name.
$value mixed Value to set.
리턴 void

_loadComponents() 보호된 메소드

Loads the defined components using the Component factory.
protected _loadComponents ( ) : void
리턴 void

_mergeControllerVars() 보호된 메소드

Merge components, helpers vars from parent classes.
protected _mergeControllerVars ( ) : void
리턴 void

_viewPath() 보호된 메소드

Get the viewPath based on controller name and request prefix.
protected _viewPath ( ) : string
리턴 string

afterFilter() 공개 메소드

Called after the controller action is run and rendered.
public afterFilter ( Cake\Event\Event $event ) : Response | null
$event Cake\Event\Event An Event instance
리턴 Cake\Network\Response | null

beforeFilter() 공개 메소드

Called before the controller action. You can use this method to configure and customize components or perform logic that needs to happen before each controller action.
public beforeFilter ( Cake\Event\Event $event ) : Response | null
$event Cake\Event\Event An Event instance
리턴 Cake\Network\Response | null

beforeRedirect() 공개 메소드

If the event is stopped the controller will not continue on to redirect the request. The $url and $status variables have same meaning as for the controller's method. You can set the event result to response instance or modify the redirect location using controller's response instance.
public beforeRedirect ( Cake\Event\Event $event, string | array $url, Response $response ) : Response | null
$event Cake\Event\Event An Event instance
$url string | array A string or array-based URL pointing to another location within the app, or an absolute URL
$response Cake\Network\Response The response object.
리턴 Cake\Network\Response | null

beforeRender() 공개 메소드

Called after the controller action is run, but before the view is rendered. You can use this method to perform logic or set view variables that are required on every request.
public beforeRender ( Cake\Event\Event $event ) : Response | null
$event Cake\Event\Event An Event instance
리턴 Cake\Network\Response | null

components() 공개 메소드

If called with the first parameter, it will be set as the controller $this->_components property
public components ( Cake\Controller\ComponentRegistry | null $components = null ) : Cake\Controller\ComponentRegistry
$components Cake\Controller\ComponentRegistry | null Component registry.
리턴 Cake\Controller\ComponentRegistry

implementedEvents() 공개 메소드

You can override this function to add your own listener callbacks
public implementedEvents ( ) : array
리턴 array

initialize() 공개 메소드

Implement this method to avoid having to overwrite the constructor and call parent.
public initialize ( ) : void
리턴 void

invokeAction() 공개 메소드

Dispatches the controller action. Checks that the action exists and isn't private.
public invokeAction ( ) : mixed
리턴 mixed The resulting response.

isAction() 공개 메소드

Override this method to change which controller methods can be reached. The default implementation disallows access to all methods defined on Cake\Controller\Controller, and allows all public methods on all subclasses of this class.
public isAction ( string $action ) : boolean
$action string The action to check.
리턴 boolean Whether or not the method is accessible from a URL.

loadComponent() 공개 메소드

This method will also set the component to a property. For example: $this->loadComponent('Acl.Acl'); Will result in a Toolbar property being set.
public loadComponent ( string $name, array $config = [] ) : Component
$name string The name of the component to load.
$config array The config for the component.
리턴 Component

paginate() 공개 메소드

Will load the referenced Table object, and have the PaginatorComponent paginate the query using the request date and settings defined in $this->paginate. This method will also make the PaginatorHelper available in the view.
public paginate ( Table | string | Query | null $object = null, array $settings = [] ) : Cake\ORM\ResultSet
$object Cake\ORM\Table | string | Cake\ORM\Query | null Table to paginate (e.g: Table instance, 'TableName' or a Query object)
$settings array The settings/configuration used for pagination.
리턴 Cake\ORM\ResultSet Query results

redirect() 공개 메소드

Redirects to given $url, after turning off $this->autoRender.
public redirect ( string | array $url, integer $status = 302 ) : Response | null
$url string | array A string or array-based URL pointing to another location within the app, or an absolute URL
$status integer HTTP status code (eg: 301)
리턴 Cake\Network\Response | null

referer() 공개 메소드

Returns the referring URL for this request.
public referer ( string | array | null $default = null, boolean $local = false ) : string
$default string | array | null Default URL to use if HTTP_REFERER cannot be read from headers
$local boolean If true, restrict referring URLs to local server
리턴 string Referring URL

render() 공개 메소드

Instantiates the correct view class, hands it its data, and uses it to render the view output.
public render ( string | null $view = null, string | null $layout = null ) : Response
$view string | null View to use for rendering
$layout string | null Layout to use
리턴 Cake\Network\Response A response object containing the rendered view.

setAction() 공개 메소드

Examples: setAction('another_action'); setAction('action_with_parameters', $parameter1);
public setAction ( string $action ) : mixed
$action string The new action to be 'redirected' to. Any other parameters passed to this method will be passed as parameters to the new action.
리턴 mixed Returns the return value of the called action

setRequest() 공개 메소드

- $this->request - To the $request parameter - $this->plugin - To the $request->params['plugin'] - $this->passedArgs - Same as $request->params['pass] - View::$plugin - $this->plugin
public setRequest ( Cake\Network\Request $request ) : void
$request Cake\Network\Request Request instance.
리턴 void

shutdownProcess() 공개 메소드

Fire the Components and Controller callbacks in the correct order. - triggers the component shutdown callback. - calls the Controller's afterFilter method.
public shutdownProcess ( ) : Response | null
리턴 Cake\Network\Response | null

startupProcess() 공개 메소드

Fire the Components and Controller callbacks in the correct order. - Initializes components, which fires their initialize callback - Calls the controller beforeFilter. - triggers Component startup methods.
public startupProcess ( ) : Response | null
리턴 Cake\Network\Response | null

프로퍼티 상세

$View 공개적으로 프로퍼티

Instance of the View created during rendering. Won't be set until after Controller::render() is called.
사용 중단: 3.1.0 Use viewBuilder() instead.
public View,Cake\View $View
리턴 Cake\View\View

$_components 보호되어 있는 프로퍼티

Instance of ComponentRegistry used to create Components
protected ComponentRegistry,Cake\Controller $_components
리턴 Cake\Controller\ComponentRegistry

$_responseClass 보호되어 있는 프로퍼티

The class name to use for creating the response object.
protected string $_responseClass
리턴 string

$_validViewOptions 보호되어 있는 프로퍼티

These Controller properties will be passed from the Controller to the View as options.
또한 보기: Cake\View\View
protected array $_validViewOptions
리턴 array

$autoRender 공개적으로 프로퍼티

Set to true to automatically render the view after action logic.
public bool $autoRender
리턴 boolean

$components 공개적으로 프로퍼티

Example: public $components = ['RequestHandler', 'Acl'];
public array $components
리턴 array

$helpers 공개적으로 프로퍼티

Example: public $helpers = ['Form', 'Html', 'Time'];
public array $helpers
리턴 array

$name 공개적으로 프로퍼티

Set automatically using conventions in Controller::__construct().
public string $name
리턴 string

$paginate 공개적으로 프로퍼티

Used to pre-configure pagination preferences for the various tables your controller will be paginating.
또한 보기: Cake\Controller\Component\PaginatorComponent
public array $paginate
리턴 array

$passedArgs 공개적으로 프로퍼티

Holds all passed params.
사용 중단: 3.1.0 Use `$this->request->params['pass']` instead.
public array $passedArgs
리턴 array

$plugin 공개적으로 프로퍼티

Automatically set to the name of a plugin.
public string $plugin
리턴 string

$request 공개적으로 프로퍼티

This object contains all the information about a request and several methods for reading additional information about the request.
public Request,Cake\Network $request
리턴 Cake\Network\Request

$response 공개적으로 프로퍼티

An instance of a Response object that contains information about the impending response
public Response,Cake\Network $response
리턴 Cake\Network\Response