Skip to content
This repository was archived by the owner on Sep 19, 2019. It is now read-only.

Configuration

sitedyno edited this page Dec 3, 2010 · 6 revisions

Filter Component Configuration Options

These should normally be passed via the $components variable of your controller:

var $components = array(
  'Filter.Filter' => array(
    'actions' => array('index')
 ));

Component Properties:

actions

An array of actions the component is allowed to filter on. Defaults to array(‘index’), Example:

var $components = array(
  'Filter.Filter' => array(
    'actions' => array('index', 'admin_index')
));

autoAssign

If true then assign the query to Controller::$paginate. Defaults to true. Example:

var $components = array(
  'Filter.Filter' => array(
    'autoAssign' => false
));

defaultDateFormat

Default date format. Defaults to ‘Y-m-d’. If you use datetime fields, this format must be ‘Y-m-d H:i’ or the form helper will not set the date correctly. Example:

var $components = array(
  'Filter.Filter' => array(
    'defaultDateFormat' => 'Y-m-d H:i'
));

defaultOperator

Default operator to use for simple queries, defaults to LIKE. Use null for =. Example:

var $components = array(
  'Filter.Filter' => array(
    'defaultOperator' => null
));

defaultTimeFormat

Default time format, defaults to ‘H:i’. Example:

var $components = array(
  'Filter.Filter' => array(
    'defaultTimeFormat' => 'H'
));

formattedFields

Array of field => regexp that dictates urlencoding and sanitization . Your regexp must use capturing fields ie: (). If the pattern is not matched the field will be dropped from the query. Example:

var $components = array(
  'Filter.Filter' => array(
    'formattedFields' => array(
    // index/Bar.length:1'11" (and no I haven't checked to see if this regexp works :p)
      'Bar.length' => '/([\d]*)\'([\d]*)\"/'
));

ignoredFIelds

Array of fields that should not be filtered on. Defaults to array(). Example:

var $components = array(
  'Filter.Filter' => array(
    'ignoredFields' => array('User.password')
));

redirect

If true then redirect and add query data to the new URL. Defaults to true. Example:

var $components = array(
  'Filter.Filter' => array(
    'redirect' => false
));

sanitizeForRedirect

If true then sanitize values for redirect using Sanitize::clean(). Defaults to true. Example:

var $components = array(
  'Filter.Filter' => array(
    'sanitizeForRedirect' => false
));

sanitizeRedirectSettings

Settings for Sanitize::clean(). Defaults to array(‘remove_html’ => true). For more info see: http://api.cakephp.org/class/sanitize#method-Sanitizeclean Example:

var $components = array(
  'Filter.Filter' => array(
    'sanitizeRedirectSettings' => array(
      'remove_html' => true,
      'odd_spaces' => true
));

sanitizeForQuery

If true then sanitize values for query. Defaults to true. Example:

var $components = array(
  'Filter.Filter' => array(
    'sanitizeForQuery' => false
));

sanitizeQuerySettings

Settings for Sanitize::clean() Default is array(‘encode’ => false). For more information see http://api.cakephp.org/class/sanitize#method-Sanitizeclean Example:

var $components = array(
  'Filter.Filter' => array(
    'sanitizeQuerySettings' => array('encode' => true)
));

spaceIsWildcard

If true then treat spaces in values as SQL wildcards ‘%’. Defaults to true. Example:

var $components = array(
  'Filter.Filter' => array(
    'spaceIsWildcard' => false
));

urlencode

If true then urlencode values before redirect. Defaults to true. Example:

var $components = array(
  'Filter.Filter' => array(
    'urlencode' => false
));

virtualFields

Assign your real fields to a virtual field type. Defaults to array(). Example:

var $components = array(
  'Filter.Filter' => array(
    'virtualFields' => array('Post.created' => 'date_range')
));

virtualFieldSeparator

This defines the character used to separate the virtual field name from its sub field name. Defaults to ‘-’.

var $components = array(
  'Filter.Filter' => array(
    'virtualFieldSeparator' => '-'
));

wrapWildcards

If true then all data values will be wrapped in SQL wildcards ‘%some value%’. Defaults to true. Example:

var $components = array(
  'Filter.Filter' => array(
    'wrapWildcards' => false
));