Application Controller
Add your application-wide methods in the class below, your controllers will inherit them.
Controller implements CakeEventListener
AppController __construct( CakeRequest $request null , CakeResponse $response null )
Constructor.
CakeRequest $request optional null CakeResponse $response optional null Object::__construct() __get( string $name )
Provides backwards compatibility access to the request object properties. Also provides the params alias.
$name mixed__isset( string $name )
Provides backwards compatibility to avoid problems with empty and isset to alias properties. Lazy loads models using the loadModel() method if declared in $uses
$name boolean__set( string $name , mixed $value )
Provides backwards compatibility access for setting values to the request object.
$name $value _afterScaffoldSave( string $method )
Alias to afterScaffoldSave()
$method booleanController::afterScaffoldSave()_afterScaffoldSaveError( string $method )
Alias to afterScaffoldSaveError()
$method booleanController::afterScaffoldSaveError()_beforeScaffold( string $method )
Alias to beforeScaffold()
$method booleanController::beforeScaffold()_getScaffold( CakeRequest $request )
Returns a scaffold object to use for dynamically scaffolded controllers.
CakeRequest $request Scaffold_getViewObject( )
Constructs the view class instance based on the controller property
View_isPrivateAction( ReflectionMethod $method , CakeRequest $request )
Check if the request's action is marked as private, with an underscore, or if the request is attempting to directly accessing a prefixed action.
$method CakeRequest $request boolean_mergeControllerVars( )
Merge components, helpers, and uses vars from Controller::$_mergeParent and PluginAppController.
_mergeUses( array $merge )
Helper method for merging the $uses property together.
Merges the elements not already in $this->uses into $this->uses.
$merge _parseBeforeRedirect( mixed $response , string|array $url , integer $status , boolean $exit )
Parse beforeRedirect Response
$response $url $status $exit array_scaffoldError( string $method )
Alias to scaffoldError()
$method booleanController::scaffoldError()afterFilter( )
Called after the controller action is run and rendered.
afterScaffoldSave( string $method )
This method should be overridden in child classes.
$method booleanafterScaffoldSaveError( string $method )
This method should be overridden in child classes.
$method booleanbeforeFilter( )
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( string|array $url , integer $status null , boolean $exit true )
The beforeRedirect method is invoked when the controller's redirect method is called but before any further action.
If this method returns false the controller will not continue on to redirect the request. The $url, $status and $exit variables have same meaning as for the controller's method. You can also return a string which will be interpreted as the URL to redirect to or return associative array with key 'url' and optionally 'status' and 'exit'.
$url $status optional null $exit optional true mixedbeforeRender( )
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.
beforeScaffold( string $method )
This method should be overridden in child classes.
$method booleanconstructClasses( )
Loads Model classes based on the uses property see Controller::loadModel(); for more info. Loads Components and prepares them for initialization.
mixedMissingModelExceptionController::loadModel()disableCache( )
Forces the user's browser not to cache the results of the current request.
flash( string $message , string|array $url , integer $pause 1 , string $layout 'flash' )
Shows a message to the user for $pause seconds, then redirects to $url. Uses flash.ctp as the default layout for the message. Does not work if the current debug level is higher than 0.
$message $url $pause optional 1 $layout optional 'flash' getEventManager( )
Returns the CakeEventManager manager instance that is handling any callbacks. You can use this instance to register any new listeners or callbacks to the controller events, or create your own events and trigger them at will.
CakeEventManagerheader( string $status )
Convenience and object wrapper method for CakeResponse::header().
$status httpCodes( integer|array $code null )
Queries & sets valid HTTP response codes & messages.
$code optional null arrayimplementedEvents( )
Returns a list of all events that will fire in the controller during its lifecycle. You can override this function to add your own listener callbacks
arrayCakeEventListener::implementedEvents() invokeAction( CakeRequest $request )
Dispatches the controller action. Checks that the action exists and isn't private.
CakeRequest $request mixedPrivateActionExceptionMissingActionExceptionloadModel( string $modelClass null , integer|string $id null )
Loads and instantiates models required by this controller. If the model is non existent, it will throw a missing database table error, as CakePHP generates dynamic models for the time being.
$modelClass optional null $id optional null booleanMissingModelExceptionpaginate( Model|string $object null , string|array $scope array() , array $whitelist array() )
Handles automatic pagination of model records.
Model|string $object optional null $scope optional array() $whitelist optional array() arraypostConditions( array $data array() , string|array $op null , string $bool 'AND' , boolean $exclusive false )
Converts POST'ed form data to a model conditions array, suitable for use in a Model::find() call.
$data optional array() $op optional null $bool optional 'AND' $exclusive optional false array|nullredirect( string|array $url , integer|array|null $status null , boolean $exit true )
Redirects to given $url, after turning off $this->autoRender. Script execution is halted after the redirect.
$url $status optional null $exit optional true referer( string $default null , boolean $local false )
Returns the referring URL for this request.
$default optional null $local optional false stringrender( string $view null , string $layout null )
Instantiates the correct view class, hands it its data, and uses it to render the view output.
$view optional null $layout optional null CakeResponsescaffoldError( string $method )
This method should be overridden in child classes. If not it will render a scaffold error. Method MUST return true in child classes
$method booleanset( string|array $one , string|array $two null )
Saves a variable for use inside a view template.
$one $two optional null setAction( string $action )
Internally redirects one action to another. Does not perform another HTTP request unlike Controller::redirect()
Examples:
setAction('another_action'); setAction('action_with_parameters', $parameter1);
$action mixedsetRequest( CakeRequest $request )
Sets the request objects and configures a number of controller properties based on the contents of the request. The properties that get set are
CakeRequest $request shutdownProcess( )
Perform the various shutdown processes for this controller. Fire the Components and Controller callbacks in the correct order.
shutdown callback.afterFilter method.startupProcess( )
Perform the startup process for this controller. Fire the Components and Controller callbacks in the correct order.
initialize callbackbeforeFilter.startup methods.validate( )
Returns number of errors in a submitted FORM.
integervalidateErrors( )
Validates models passed by parameters. Takes a list of models as a variable argument. Example:
$errors = $this->validateErrors($this->Article, $this->User);
array_mergeVars( array $properties , string $class , boolean $normalize true )
Merges this objects $property with the property in $class' definition. This classes value for the property will be merged on top of $class'
This provides some of the DRY magic CakePHP provides. If you want to shut it off, redefine this method as an empty function.
$properties $class $normalize optional true _set( array $properties array() )
Allows setting of multiple properties of the object in a single line of code. Will only set properties that are part of a class declaration.
$properties optional array() _stop( integer|string $status 0 )
Stop execution of the current script. Wraps exit() making testing easier.
$status optional 0 dispatchMethod( string $method , array $params array() )
Calls a method on this object with the given parameters. Provides an OO wrapper for call_user_func_array
$method $params optional array() mixedlog( string $msg , integer $type LOG_ERR , null|string|array $scope null )
Convenience method to write a message to CakeLog. See CakeLog::write() for more information on writing to logs.
$msg $type optional LOG_ERR $scope optional null booleanrequestAction( string|array $url , array $extra array() )
Calls a controller's method from any location. Can be used to connect controllers together or tie plugins into a main application. requestAction can be used to return rendered views or fetch the return value from controller actions.
Under the hood this method uses Router::reverse() to convert the $url parameter into a string URL. You should use URL formats that are compatible with Router::reverse()
POST and GET data can be simulated in requestAction. Use $extra['url'] for GET data. The $extra['data'] parameter allows POST data simulation.
$url $extra optional array() mixedtoString( )
Object-to-string conversion. Each class can override this method as necessary.
string public ComponentCollection
Instance of ComponentCollection used to handle callbacks.
null public View
Instance of the View created during rendering. Won't be set until after Controller::render() is called.
protected CakeEventManager
Instance of the CakeEventManager this controller is using to dispatch inner events.
null protected string
The class name of the parent class you wish to merge with. Typically this is AppController, but you may wish to merge vars with a different parent class.
'AppController' protected string
The class name to use for creating the response object.
'CakeResponse' public boolean
Set to true to automatically render the view after action logic.
true public mixed
Used to define methods a controller that will be cached. To cache a single action, the value is set to an array containing keys that match action names and values that denote cache expiration times (in seconds).
Example:
public $cacheAction = array( 'view/23/' => 21600, 'recalled/' => 86400 );
$cacheAction can also be set to a strtotime() compatible string. This marks all the actions in the controller for view caching.
false public array
Array containing the names of components this controller uses. Component names should not contain the "Component" portion of the class name.
Example: public $components = array('Session', 'RequestHandler', 'Acl');
array('Session', 'Flash')
public string
File extension for view templates. Defaults to CakePHP's conventional ".ctp".
'.ctp' public mixed
An array containing the names of helpers this controller uses. The array elements should not contain the "Helper" part of the class name.
Example: public $helpers = array('Html', 'Js', 'Time', 'Ajax');
array() public string
The name of the layout file to render the view inside of. The name specified is the filename of the layout in /app/View/Layouts without the .ctp extension.
'default' public string
The name of the layouts subfolder containing layouts for this controller.
null public array
Holds current methods of the controller. This is a list of all the methods reachable via URL. Modifying this array will allow you to change which methods can be reached.
array() public string
This controller's primary model class name, the Inflector::singularize()'ed version of the controller's $name property.
Example: For a controller named 'Comments', the modelClass would be 'Comment'
null public string
This controller's model key name, an underscored version of the controller's $modelClass property.
Example: For a controller named 'ArticleComments', the modelKey would be 'article_comment'
null public string
The name of this controller. Controller names are plural, named after the model they manipulate.
null public CakeRequest
An instance of a CakeRequest object that contains information about the current request. This object contains all the information about a request and several methods for reading additional information about the request.
public CakeResponse
An instance of a CakeResponse object that contains information about the impending response
public mixed
Triggers Scaffolding
false public mixed
An array containing the class names of models this controller uses.
Example: public $uses = array('Product', 'Post', 'Comment');
Can be set to several values to express different options:
true Use the default inflected model name.array() Use only models defined in the parent class.false Use no models at all, do not merge with parent class either.array('Post', 'Comment') Use only the Post and Comment models. Models Will also be merged with the parent class.The default value is true.
true public array
Holds any validation errors produced by the last call of the validateErrors() method.
null public string
The name of the view file to render. The name specified is the filename in /app/View/<SubFolder> without the .ctp extension.
null public string
The name of the views subfolder containing views for this controller.
null public AclComponent
public AuthComponent
public CookieComponent
public EmailComponent
public PaginatorComponent
public RequestHandlerComponent
public SecurityComponent
public SessionComponent
© 2005–2016 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
http://api.cakephp.org/2.7/class-AppController.html