CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (GitHub)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • Slack
    • Paid Support
CakePHP

C CakePHP 1.3 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 1.3
      • 4.2
      • 4.1
      • 4.0
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Classes

  • AclBase
  • AclBehavior
  • AclComponent
  • AclNode
  • AclShell
  • Aco
  • AcoAction
  • AjaxHelper
  • ApcEngine
  • ApiShell
  • App
  • AppController
  • AppHelper
  • AppModel
  • Aro
  • AuthComponent
  • BakeShell
  • BakeTask
  • BehaviorCollection
  • Cache
  • CacheEngine
  • CacheHelper
  • CakeErrorController
  • CakeLog
  • CakeRoute
  • CakeSchema
  • CakeSession
  • CakeSocket
  • ClassRegistry
  • Component
  • Configure
  • ConnectionManager
  • ConsoleShell
  • ContainableBehavior
  • Controller
  • ControllerTask
  • CookieComponent
  • DataSource
  • DbAcl
  • DbConfigTask
  • DboMssql
  • DboMysql
  • DboMysqlBase
  • DboMysqli
  • DboOracle
  • DboPostgres
  • DboSource
  • DboSqlite
  • Debugger
  • EmailComponent
  • ErrorHandler
  • ExtractTask
  • File
  • FileEngine
  • FileLog
  • FixtureTask
  • Folder
  • FormHelper
  • Helper
  • HtmlHelper
  • HttpSocket
  • I18n
  • I18nModel
  • I18nShell
  • Inflector
  • IniAcl
  • JavascriptHelper
  • JqueryEngineHelper
  • JsBaseEngineHelper
  • JsHelper
  • L10n
  • MagicDb
  • MagicFileResource
  • MediaView
  • MemcacheEngine
  • Model
  • ModelBehavior
  • ModelTask
  • MootoolsEngineHelper
  • Multibyte
  • NumberHelper
  • Object
  • Overloadable
  • Overloadable2
  • PagesController
  • PaginatorHelper
  • Permission
  • PluginShortRoute
  • PluginTask
  • ProjectTask
  • PrototypeEngineHelper
  • RequestHandlerComponent
  • Router
  • RssHelper
  • Sanitize
  • Scaffold
  • ScaffoldView
  • SchemaShell
  • Security
  • SecurityComponent
  • SessionComponent
  • SessionHelper
  • Set
  • Shell
  • String
  • TemplateTask
  • TestSuiteShell
  • TestTask
  • TextHelper
  • ThemeView
  • TimeHelper
  • TranslateBehavior
  • TreeBehavior
  • Validation
  • View
  • ViewTask
  • XcacheEngine
  • Xml
  • XmlElement
  • XmlHelper
  • XmlManager
  • XmlNode
  • XmlTextNode

Functions

  • mb_encode_mimeheader
  • mb_stripos
  • mb_stristr
  • mb_strlen
  • mb_strpos
  • mb_strrchr
  • mb_strrichr
  • mb_strripos
  • mb_strrpos
  • mb_strstr
  • mb_strtolower
  • mb_strtoupper
  • mb_substr
  • mb_substr_count

Class RequestHandlerComponent

Request object for handling HTTP requests

Object
Extended by RequestHandlerComponent
Package: cake\cake\libs\controller\components
Link: http://book.cakephp.org/1.3/en/The-Manual/Core-Components/Request-Handling.html
Copyright: Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
License: License (http://www.opensource.org/licenses/mit-license.php)
Location: controller/components/request_handler.php

Properties summary

  • $__acceptTypes public
    array

    Content-types accepted by the client. If extension parsing is enabled in the Router, and an extension is detected, the corresponding content-type will be used as the overriding primary content-type accepted.

  • $__renderType public
    string
    The template to use when rendering the given content type.
  • $__requestContent public
    array

    Friendly content-type mappings used to set response types and determine request types. Can be modified with RequestHandler::setContent()

  • $__responseTypeSet public
    string

    Holds the content-type of the response that is set when using RequestHandler::respondAs()

  • $__typesInitialized public
    boolean
    Flag set when MIME types have been initialized
  • $ajaxLayout public
    string
    The layout that will be switched to for Ajax requests
  • $enabled public
    boolean
    Determines whether or not callbacks will be fired on this component
  • $ext public
    string
    Contains the file extension parsed out by the Router
  • $mobileUA public
    array
    List of regular expressions for matching mobile device's user agent string
  • $params public
    array
    Holds the copy of Controller::$params

Method Summary

  • __construct() public
    Constructor. Parses the accepted content types accepted by the client using HTTP_ACCEPT
  • __initializeTypes() public
    Initializes MIME types
  • _header() public
    Wrapper for header() so calls can be easily tested.
  • accepts() public

    Determines which content types the client accepts. Acceptance is based on the file extension parsed by the Router (if present), and by the HTTP_ACCEPT header.

  • beforeRedirect() public
    Handles (fakes) redirects for Ajax requests using requestAction()
  • getAjaxVersion() public

    Gets Prototype version if call is Ajax, otherwise empty string. The Prototype library sets a special "Prototype version" HTTP header.

  • getClientIP() public
    Gets remote client IP
  • getReferer() public
    Gets the server name from which this request was referred
  • initialize() public

    Initializes the component, gets a reference to Controller::$parameters, and checks to see if a file extension has been parsed by the Router. If yes, the corresponding content-type is pushed onto the list of accepted content-types as the first item.

  • isAjax() public
    Returns true if the current HTTP request is Ajax, false otherwise
  • isAtom() public
    Returns true if the current call accepts an Atom response, false otherwise
  • isDelete() public
    Returns true if the current call a DELETE request
  • isFlash() public
    Returns true if the current HTTP request is coming from a Flash-based client
  • isGet() public
    Returns true if the current call a GET request
  • isMobile() public deprecated

    Returns true if user agent string matches a mobile web browser, or if the client accepts WAP content.

  • isPost() public
    Returns true if the current call a POST request
  • isPut() public
    Returns true if the current call a PUT request
  • isRss() public
    Returns true if the current call accepts an RSS response, false otherwise
  • isSSL() public
    Returns true if the current request is over HTTPS, false otherwise.
  • isWap() public
    Returns true if the client accepts WAP content
  • isXml() public
    Returns true if the current call accepts an XML response, false otherwise
  • mapType() public
    Maps a content-type back to an alias
  • prefers() public

    Determines which content-types the client prefers. If no parameters are given, the content-type that the client most likely prefers is returned. If $type is an array, the first item in the array that the client accepts is returned. Preference is determined primarily by the file extension parsed by the Router if provided, and secondarily by the list of content-types provided in HTTP_ACCEPT.

  • renderAs() public
    Sets the layout and template paths for the content type defined by $type.
  • requestedWith() public
    Determines the content type of the data the client has sent (i.e. in a POST request)
  • respondAs() public

    Sets the response header based on type map index name. If DEBUG is greater than 2, the header is not set.

  • responseType() public
    Returns the current response type (Content-type header), or null if none has been set
  • setContent() public

    Adds/sets the Content-type(s) for the given name. This method allows content-types to be mapped to friendly aliases (or extensions), which allows RequestHandler to automatically respond to requests of that type in the startup method.

  • startup() public

    The startup method of the RequestHandler enables several automatic behaviors related to the detection of certain properties of the HTTP request, including:

Method Detail

__construct() public ¶

__construct( )

Constructor. Parses the accepted content types accepted by the client using HTTP_ACCEPT

Overrides
Object::__construct()

__initializeTypes() public ¶

__initializeTypes( )

Initializes MIME types

_header() public ¶

_header( string $header )

Wrapper for header() so calls can be easily tested.

Parameters
string $header
The header to be sent.

accepts() public ¶

accepts( mixed $type = null )

Determines which content types the client accepts. Acceptance is based on the file extension parsed by the Router (if present), and by the HTTP_ACCEPT header.

Parameters
mixed $type optional null

Can be null (or no parameter), a string type name, or an array of types

Returns
mixed

If null or no parameter is passed, returns an array of content types the client accepts. If a string is passed, returns true if the client accepts it. If an array is passed, returns true if the client accepts one or more elements in the array.


See
RequestHandlerComponent::setContent()

beforeRedirect() public ¶

beforeRedirect( object $controller , mixed $url , mixed $status = null )

Handles (fakes) redirects for Ajax requests using requestAction()

Parameters
object $controller
A reference to the controller
mixed $url
A string or array containing the redirect location
mixed $status optional null
Status for redirect

getAjaxVersion() public ¶

getAjaxVersion( )

Gets Prototype version if call is Ajax, otherwise empty string. The Prototype library sets a special "Prototype version" HTTP header.

Returns
string
Prototype version of component making Ajax call

getClientIP() public ¶

getClientIP( $safe = true )

Gets remote client IP

Returns
string
Client IP address

getReferer() public ¶

getReferer( )

Gets the server name from which this request was referred

Returns
string
Server address

initialize() public ¶

initialize( object $controller , array $settings = array() )

Initializes the component, gets a reference to Controller::$parameters, and checks to see if a file extension has been parsed by the Router. If yes, the corresponding content-type is pushed onto the list of accepted content-types as the first item.

Parameters
object $controller
A reference to the controller
array $settings optional array()
Array of settings to _set().
See
Router::parseExtensions()

isAjax() public ¶

isAjax( )

Returns true if the current HTTP request is Ajax, false otherwise

Returns
boolean
True if call is Ajax

isAtom() public ¶

isAtom( )

Returns true if the current call accepts an Atom response, false otherwise

Returns
boolean
True if client accepts an RSS response

isDelete() public ¶

isDelete( )

Returns true if the current call a DELETE request

Returns
boolean
True if call is a DELETE

isFlash() public ¶

isFlash( )

Returns true if the current HTTP request is coming from a Flash-based client

Returns
boolean
True if call is from Flash

isGet() public ¶

isGet( )

Returns true if the current call a GET request

Returns
boolean
True if call is a GET

isMobile() public deprecated ¶

isMobile( )

Returns true if user agent string matches a mobile web browser, or if the client accepts WAP content.

Deprecated
Use of constant REQUEST_MOBILE_UA is deprecated and will be removed in future versions
Returns
boolean
True if user agent is a mobile web browser

isPost() public ¶

isPost( )

Returns true if the current call a POST request

Returns
boolean
True if call is a POST

isPut() public ¶

isPut( )

Returns true if the current call a PUT request

Returns
boolean
True if call is a PUT

isRss() public ¶

isRss( )

Returns true if the current call accepts an RSS response, false otherwise

Returns
boolean
True if client accepts an RSS response

isSSL() public ¶

isSSL( )

Returns true if the current request is over HTTPS, false otherwise.

Returns
boolean
True if call is over HTTPS

isWap() public ¶

isWap( )

Returns true if the client accepts WAP content

Returns
boolean

isXml() public ¶

isXml( )

Returns true if the current call accepts an XML response, false otherwise

Returns
boolean
True if client accepts an XML response

mapType() public ¶

mapType( mixed $ctype )

Maps a content-type back to an alias

Parameters
mixed $ctype
$type Content type
Returns
mixed
Alias

prefers() public ¶

prefers( mixed $type = null )

Determines which content-types the client prefers. If no parameters are given, the content-type that the client most likely prefers is returned. If $type is an array, the first item in the array that the client accepts is returned. Preference is determined primarily by the file extension parsed by the Router if provided, and secondarily by the list of content-types provided in HTTP_ACCEPT.

Parameters
mixed $type optional null

An optional array of 'friendly' content-type names, i.e. 'html', 'xml', 'js', etc.

Returns
mixed

If $type is null or not provided, the first content-type in the list, based on preference, is returned.


See
RequestHandlerComponent::setContent()

renderAs() public ¶

renderAs( object $controller , string $type )

Sets the layout and template paths for the content type defined by $type.

Parameters
object $controller
A reference to a controller object
string $type
Type of response to send (e.g: 'ajax')
See
RequestHandlerComponent::setContent()
RequestHandlerComponent::respondAs()

requestedWith() public ¶

requestedWith( mixed $type = null )

Determines the content type of the data the client has sent (i.e. in a POST request)

Parameters
mixed $type optional null
Can be null (or no parameter), a string type name, or an array of types
Returns
mixed

respondAs() public ¶

respondAs( mixed $type , array $options = array() )

Sets the response header based on type map index name. If DEBUG is greater than 2, the header is not set.

Parameters
mixed $type

Friendly type name, i.e. 'html' or 'xml', or a full content-type, like 'application/x-shockwave'.

array $options optional array()

If $type is a friendly type name that is associated with more than one type of content, $index is used to select which content-type to use.

Returns
boolean

Returns false if the friendly type name given in $type does not exist in the type map, or if the Content-type header has already been set by this method.


See
RequestHandlerComponent::setContent()

responseType() public ¶

responseType( )

Returns the current response type (Content-type header), or null if none has been set

Returns
mixed

A string content type alias, or raw content type if no alias map exists, otherwise null


setContent() public ¶

setContent( string $name , mixed $type = null )

Adds/sets the Content-type(s) for the given name. This method allows content-types to be mapped to friendly aliases (or extensions), which allows RequestHandler to automatically respond to requests of that type in the startup method.

Parameters
string $name
The name of the Content-type, i.e. "html", "xml", "css"
mixed $type optional null

The Content-type or array of Content-types assigned to the name, i.e. "text/html", or "application/xml"

startup() public ¶

startup( object $controller )

The startup method of the RequestHandler enables several automatic behaviors related to the detection of certain properties of the HTTP request, including:

  • Disabling layout rendering for Ajax requests (based on the HTTP_X_REQUESTED_WITH header)
  • If Router::parseExtensions() is enabled, the layout and template type are switched based on the parsed extension. For example, if controller/action.xml is requested, the view path becomes app/views/controller/xml/action.ctp.
  • If a helper with the same name as the extension exists, it is added to the controller.
  • If the extension is of a type that RequestHandler understands, it will set that Content-type in the response header.
  • If the XML data is POSTed, the data is parsed into an XML object, which is assigned to the $data property of the controller, which can then be saved to a model object.
Parameters
object $controller
A reference to the controller

Methods inherited from Object

Object() public ¶

Object( )

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()

Returns
Object

__openPersistent() public ¶

__openPersistent( string $name , string $type = null )

Open the persistent class file for reading Used by Object::_persist()

Parameters
string $name
Name of persisted class
string $type optional null
Type of persistance (e.g: registry)

_persist() public ¶

_persist( string $name , string $return , $object , $type = null )

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
string $name
name of the class to persist
string $return
$object the object to persist
$object
$type optional null
Returns
boolean
Success

_savePersistent() public ¶

_savePersistent( string $name , object $object )

You should choose a unique name for the persistent file

There are many uses for this method, see manual for examples

Parameters
string $name
name used for object to cache
object $object
the object to persist
Returns
boolean
true on save, throws error if file can not be created

_set() public ¶

_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.

Parameters
array $properties optional array()
An associative array containing properties and corresponding values.

_stop() public ¶

_stop( $status = 0 )

Stop execution of the current script. Wraps exit() making testing easier.

Parameters
$status optional 0
http://php.net/exit for values

cakeError() public ¶

cakeError( string $method , array $messages = array() )

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
string $method
Method to be called in the error class (AppError or ErrorHandler classes)
array $messages optional array()
Message that is to be displayed by the error class
Returns
error
message

dispatchMethod() public ¶

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

Parameters
string $method
Name of the method to call
array $params optional array()
Parameter list to use when calling $method
Returns
mixed
Returns the result of the method call

log() public ¶

log( string $msg , integer $type = LOG_ERROR )

Convience method to write a message to CakeLog. See CakeLog::write() for more information on writing to logs.

Parameters
string $msg
Log message
integer $type optional LOG_ERROR
Error type constant. Defined in app/config/core.php.
Returns
boolean
Success of log write

requestAction() public ¶

requestAction( mixed $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.

Parameters
mixed $url
String or array-based url.
array $extra optional array()
if array includes the key "return" it sets the AutoRender to true.
Returns
mixed

Boolean true or false on success/failure, or contents of rendered action if 'return' is set in $extra.


toString() public ¶

toString( )

Object-to-string conversion. Each class can override this method as necessary.

Returns
string
The name of this class

Properties detail

$__acceptTypes ¶

public array

Content-types accepted by the client. If extension parsing is enabled in the Router, and an extension is detected, the corresponding content-type will be used as the overriding primary content-type accepted.

See
Router::parseExtensions()
array()

$__renderType ¶

public string

The template to use when rendering the given content type.

null

$__requestContent ¶

public array

Friendly content-type mappings used to set response types and determine request types. Can be modified with RequestHandler::setContent()

See
RequestHandlerComponent::setContent
array(
    'javascript'    => 'text/javascript',
    'js'            => 'text/javascript',
    'json'          => 'application/json',
    'css'           => 'text/css',
    'html'          => array('text/html', '*/*'),
    'text'          => 'text/plain',
    'txt'           => 'text/plain',
    'csv'           => array('text/csv', 'application/vnd.ms-excel', 'text/plain'),
    'form'          => 'application/x-www-form-urlencoded',
    'file'          => 'multipart/form-data',
    'xhtml'         => array('application/xhtml+xml', 'application/xhtml', 'text/xhtml'),
    'xhtml-mobile'  => 'application/vnd.wap.xhtml+xml',
    'xml'           => array('application/xml', 'text/xml'),
    'rss'           => 'application/rss+xml',
    'atom'          => 'application/atom+xml',
    'amf'           => 'application/x-amf',
    'wap'           => array(
        'text/vnd.wap.wml',
        'text/vnd.wap.wmlscript',
        'image/vnd.wap.wbmp'
    ),
    'wml'           => 'text/vnd.wap.wml',
    'wmlscript'     => 'text/vnd.wap.wmlscript',
    'wbmp'          => 'image/vnd.wap.wbmp',
    'pdf'           => 'application/pdf',
    'zip'           => 'application/x-zip',
    'tar'           => 'application/x-tar'
)

$__responseTypeSet ¶

public string

Holds the content-type of the response that is set when using RequestHandler::respondAs()

null

$__typesInitialized ¶

public boolean

Flag set when MIME types have been initialized

See
RequestHandler::__initializeTypes()
false

$ajaxLayout ¶

public string

The layout that will be switched to for Ajax requests

See
RequestHandler::setAjax()
'ajax'

$enabled ¶

public boolean

Determines whether or not callbacks will be fired on this component

true

$ext ¶

public string

Contains the file extension parsed out by the Router

See
Router::parseExtensions()
null

$mobileUA ¶

public array

List of regular expressions for matching mobile device's user agent string

array(
    'Android',
    'AvantGo',
    'BlackBerry',
    'DoCoMo',
    'iPod',
    'iPhone',
    'iPad',
    'J2ME',
    'MIDP',
    'NetFront',
    'Nokia',
    'Opera Mini',
    'Opera Mobi',
    'PalmOS',
    'PalmSource',
    'portalmmm',
    'Plucker',
    'ReqwirelessWeb',
    'SonyEricsson',
    'Symbian',
    'UP\.Browser',
    'webOS',
    'Windows CE',
    'Windows Phone OS',
    'Xiino'
)

$params ¶

public array

Holds the copy of Controller::$params

array()
OpenHub
Rackspace
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (GitHub)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • Slack
  • Paid Support

Generated using CakePHP API Docs