Controller Class Info:

Class Declaration:
class Controller extends Object
File name:
cake/libs/controller/controller.php
Summary:
Controller Application controller class for organization of business logic. Provides basic functionality, such as rendering views inside layouts, automatic model availability, redirection, callbacks, and more.
Class Inheritance

Object

Properties:

Show/Hide parent properties
public action The name of the currently requested controller action.
public autoLayout Set to true to automatically render the layout around views.
public autoRender Set to true to automatically render the view after action logic.
public base Base URL path.
public cacheAction 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: var $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.
public Component Instance of Component used to handle callbacks.
public components Array containing the names of components this controller uses. Component names should not contain the "Component" portion of the classname. Example: var $components = array('Session', 'RequestHandler', 'Acl');
public data Data POSTed to the controller using the HtmlHelper. Data here is accessible using the $this->data['ModelName']['fieldName'] pattern.
public ext File extension for view templates. Defaults to Cake's conventional ".ctp".
protected helpers An array containing the names of helpers this controller uses. The array elements should not contain the "Helper" part of the classname. Example: var $helpers = array('Html', 'Javascript', 'Time', 'Ajax');
public here Stores the current URL, relative to the webroot of the application.
public layout The name of the layout file to render the view inside of. The name specified is the filename of the layout in /app/views/layouts without the .ctp extension.
public layoutPath The name of the layouts subfolder containing layouts for this controller.
protected _log Log object
public methods Holds current methods of the controller
public modelClass This controller's primary model class name, the Inflector::classify()'ed version of the controller's $name property. Example: For a controller named 'Comments', the modelClass would be 'Comment'
public modelKey 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'
public modelNames An array containing the class names of the models this controller uses.
public name The name of this controller. Controller names are plural, named after the model they manipulate.
public output The output of the requested action. Contains either a variable returned from the action, or the data of the rendered view; You can use this var in child controllers' afterFilter() callbacks to alter output.
public pageTitle Text to be used for the $title_for_layout layout variable (usually placed inside <title> tags.)
public paginate Holds pagination defaults for controller actions. The keys that can be included in this array are: 'conditions', 'fields', 'order', 'limit', 'page', and 'recursive', similar to the keys in the second parameter of Model::find(). Pagination defaults can also be supplied in a model-by-model basis by using the name of the model as a key for a pagination array: var $paginate = array( 'Post' => array(...), 'Comment' => array(...) );
public params Parameters received in the current request: GET and POST data, information about the request, etc.
public passedArgs Holds all params passed and named.
public persistModel Used to create cached instances of models a controller uses. When set to true, all models related to the controller will be cached. This can increase performance in many cases.
public plugin Automatically set to the name of a plugin.
public scaffold Triggers Scaffolding
protected uses An array containing the class names of models this controller uses. Example: var $uses = array('Product', 'Post', 'Comment'); Can be set to array() to use no models. Can be set to false to use no models and prevent the merging of $uses with AppController
public validationErrors Holds any validation errors produced by the last call of the validateErrors() method/
public view The name of the View class this controller sends output to.
public viewPath The name of the views subfolder containing views for this controller.
public viewVars Contains variables to be handed to the view.
public webroot The webroot of the application. Helpful if your application is placed in a folder under the current domain name.

afterFilter

top
Called after the controller action is run and rendered.
Method defined in class:
Controller
Method defined in file:
cake/libs/controller/controller.php on line 1143

_afterScaffoldSave

top
This method should be overridden in child classes.
Parameters:
$method string name of method called either edit or update. required (no default)
Method defined in class:
Controller
Method defined in file:
cake/libs/controller/controller.php on line 1164
return
boolean Success
access
protected
link
http://book.cakephp.org/view/60/Callbacks

_afterScaffoldSaveError

top
This method should be overridden in child classes.
Parameters:
$method string name of method called either edit or update. required (no default)
Method defined in class:
Controller
Method defined in file:
cake/libs/controller/controller.php on line 1175
return
boolean Success
access
protected
link
http://book.cakephp.org/view/60/Callbacks

beforeFilter

top
Called before the controller action.
Method defined in class:
Controller
Method defined in file:
cake/libs/controller/controller.php on line 1127

beforeRender

top
Called after the controller action is run, but before the view is rendered.
Method defined in class:
Controller
Method defined in file:
cake/libs/controller/controller.php on line 1135

_beforeScaffold

top
This method should be overridden in child classes.
Parameters:
$method string name of method called example index, edit, etc. required (no default)
Method defined in class:
Controller
Method defined in file:
cake/libs/controller/controller.php on line 1153
return
boolean Success
access
protected
link
http://book.cakephp.org/view/60/Callbacks

cakeError

top
Used to report user friendly errors. If there is a file app/error.php or app/app_error.php this file will be loaded error.php is the AppError class it should extend ErrorHandler class.
Parameters:
$method string Method to be called in the error class (AppError or ErrorHandler classes) required (no default)
$messages array Message that is to be displayed by the error class optional array ( )
Method defined in class:
Object
Method defined in file:
cake/libs/object.php on line 188
return
error message
access
public

__construct

top
Constructor.
Method defined in class:
Controller
Method defined in file:
cake/libs/controller/controller.php on line 326

constructClasses

top
Loads Model classes based on the the uses property see Controller::loadModel(); for more info. Loads Components and prepares them for initialization.
Method defined in class:
Controller
Method defined in file:
cake/libs/controller/controller.php on line 442
return
mixed true if models found and instance created, or cakeError if models not found.
access
public
see
Controller::loadModel()
link
http://book.cakephp.org/view/429/constructClasses

disableCache

top
Forces the user's browser not to cache the results of the current request.
Method defined in class:
Controller
Method defined in file:
cake/libs/controller/controller.php on line 848
return
void
access
public
link
http://book.cakephp.org/view/431/disableCache

dispatchMethod

top
Calls a method on this object with the given parameters. Provides an OO wrapper for call_user_func_array, and improves performance by using straight method calls in most cases.
Parameters:
$method string Name of the method to call required (no default)
$params array Parameter list to use when calling $method optional array ( )
Method defined in class:
Object
Method defined in file:
cake/libs/object.php on line 112
return
mixed Returns the result of the method call
access
public

flash

top
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.
Parameters:
$message string Message to display to the user required (no default)
$url mixed Relative string or array-based URL to redirect to after the time expires required (no default)
$pause integer Time to show the message optional 1
Method defined in class:
Controller
Method defined in file:
cake/libs/controller/controller.php on line 867
return
void Renders flash layout
access
public
link
http://book.cakephp.org/view/426/flash

header

top
Convenience method for header()
Parameters:
$status string required (no default)
Method defined in class:
Controller
Method defined in file:
cake/libs/controller/controller.php on line 645
return
void
access
public

isAuthorized

top
Controller callback to tie into Auth component. Only called when AuthComponent::authorize is set to 'controller'.
Method defined in class:
Controller
Method defined in file:
cake/libs/controller/controller.php on line 708
return
bool true if authorized, false otherwise
access
public
link
http://book.cakephp.org/view/396/authorize

loadModel

top
Loads and instantiates models required by this controller. If Controller::persistModel; is true, controller will create cached model instances on first request, additional request will used cached models. If the model is non existent, it will throw a missing database table error, as Cake generates dynamic models for the time being.
Parameters:
$modelClass string Name of model class to load optional NULL
$id mixed Initial ID the instanced model class should have optional NULL
Method defined in class:
Controller
Method defined in file:
cake/libs/controller/controller.php on line 481
return
mixed true when single model found and instance created error returned if models not found.
access
public

log

top
API for logging events.
Parameters:
$msg string Log message required (no default)
$type integer Error type constant. Defined in app/config/core.php. optional 2
Method defined in class:
Object
Method defined in file:
cake/libs/object.php on line 149
return
boolean Success of log write
access
public

__mergeVars

top
Merge components, helpers, and uses vars from AppController and PluginAppController.
Method defined in class:
Controller
Method defined in file:
cake/libs/controller/controller.php on line 361
return
void
access
protected

Object

top
A hack to support __construct() on PHP 4 Hint: descendant classes have no PHP4 class_name() constructors, so this constructor gets called first and calls the top-layer __construct() which (if present) should call parent::__construct()
Method defined in class:
Object
Method defined in file:
cake/libs/object.php on line 52
return
Object

paginate

top
Handles automatic pagination of model records.
Parameters:
$object mixed Model to paginate (e.g: model instance, or 'Model', or 'Model.InnerModel') optional NULL
$scope mixed Conditions to use while paginating optional array ( )
$whitelist array List of allowed options for paging optional array ( )
Method defined in class:
Controller
Method defined in file:
cake/libs/controller/controller.php on line 942
return
array Model query results
access
public
link
http://book.cakephp.org/view/165/Controller-Setup

_persist

top
Checks for a persistent class file, if found file is opened and true returned If file is not found a file is created and false returned If used in other locations of the model you should choose a unique name for the persistent file There are many uses for this method, see manual for examples
Parameters:
$name string name of the class to persist required (no default)
$return required (no default)
$object string the object to persist required (no default)
$type optional NULL
Method defined in class:
Object
Method defined in file:
cake/libs/object.php on line 218
return
boolean Success
access
protected
todo
add examples to manual

postConditions

top
Converts POST'ed form data to a model conditions array, suitable for use in a Model::find() call.
Parameters:
$data array POST'ed data organized by model and field optional array ( )
$op mixed A string containing an SQL comparison operator, or an array matching operators to fields optional NULL
$bool string SQL boolean operator: AND, OR, XOR, etc. optional 'AND'
$exclusive boolean If true, and $op is an array, fields not included in $op will not be included in the returned conditions optional false
Method defined in class:
Controller
Method defined in file:
cake/libs/controller/controller.php on line 886
return
array An array of model conditions
access
public
link
http://book.cakephp.org/view/432/postConditions

redirect

top
Redirects to given $url, after turning off $this->autoRender. Script execution is halted after the redirect.
Parameters:
$url mixed A string or array-based URL pointing to another location within the app, or an absolute URL required (no default)
$status integer Optional HTTP status code (eg: 404) optional NULL
$exit boolean If true, exit() will be called after the redirect optional true
Method defined in class:
Controller
Method defined in file:
cake/libs/controller/controller.php on line 538
return
mixed void if $exit = false. Terminates script if $exit = true
access
public
link
http://book.cakephp.org/view/425/redirect

referer

top
Returns the referring URL for this request.
Parameters:
$default string Default URL to use if HTTP_REFERER cannot be read from headers optional NULL
$local boolean If true, restrict referring URLs to local server optional false
Method defined in class:
Controller
Method defined in file:
cake/libs/controller/controller.php on line 821
return
string Referring URL
access
public
link
http://book.cakephp.org/view/430/referer

render

top
Instantiates the correct view class, hands it its data, and uses it to render the view output.
Parameters:
$action string Action name to render optional NULL
$layout string Layout to use optional NULL
$file string File to use for rendering optional NULL
Method defined in class:
Controller
Method defined in file:
cake/libs/controller/controller.php on line 764
return
string Full output string of view contents
access
public
link
http://book.cakephp.org/view/428/render

requestAction

top
Calls a controller's method from any location.
Parameters:
$url mixed String or array-based url. required (no default)
$extra array if array includes the key "return" it sets the AutoRender to true. optional array ( )
Method defined in class:
Object
Method defined in file:
cake/libs/object.php on line 85
return
mixed Boolean true or false on success/failure, or contents of rendered action if 'return' is set in $extra.
access
public

_savePersistent

top
You should choose a unique name for the persistent file There are many uses for this method, see manual for examples
Parameters:
$name string name used for object to cache required (no default)
$object object the object to persist required (no default)
Method defined in class:
Object
Method defined in file:
cake/libs/object.php on line 246
return
boolean true on save, throws error if file can not be created
access
protected

_scaffoldError

top
This method should be overridden in child classes. If not it will render a scaffold error. Method MUST return true in child classes
Parameters:
$method string name of method called example index, edit, etc. required (no default)
Method defined in class:
Controller
Method defined in file:
cake/libs/controller/controller.php on line 1188
return
boolean Success
access
protected
link
http://book.cakephp.org/view/60/Callbacks

set

top
Saves a variable for use inside a view template.
Parameters:
$one mixed A string or an array of data. required (no default)
$two mixed Value in case $one is a string (which then works as the key). Unused if $one is an associative array, otherwise serves as the values to $one's keys. optional NULL
Method defined in class:
Controller
Method defined in file:
cake/libs/controller/controller.php on line 658
return
void
access
public
link
http://book.cakephp.org/view/427/set

_set

top
Allows setting of multiple properties of the object in a single line of code.
Parameters:
$properties array An associative array containing properties and corresponding values. optional array ( )
Method defined in class:
Object
Method defined in file:
cake/libs/object.php on line 168
return
void
access
protected

setAction

top
Internally redirects one action to another. Examples: setAction('another_action'); setAction('action_with_parameters', $parameter1);
Parameters:
$action string The new action to be redirected to required (no default)
Method defined in class:
Controller
Method defined in file:
cake/libs/controller/controller.php on line 695
return
mixed Returns the return value of the called action
access
public

_stop

top
Stop execution of the current script
Parameters:
$status optional 0
Method defined in class:
Object
Method defined in file:
cake/libs/object.php on line 138
return
void
access
public

toString

top
Object-to-string conversion. Each class can override this method as necessary.
Method defined in class:
Object
Method defined in file:
cake/libs/object.php on line 72
return
string The name of this class
access
public

validate

top
Returns number of errors in a submitted FORM.
Method defined in class:
Controller
Method defined in file:
cake/libs/controller/controller.php on line 718
return
integer Number of errors
access
public

validateErrors

top
Validates models passed by parameters. Example: $errors = $this->validateErrors($this->Article, $this->User);
Method defined in class:
Controller
Method defined in file:
cake/libs/controller/controller.php on line 736
return
array Validation errors, or false if none
access
public