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 2.4 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 2.4
      • 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

Packages

  • Cake
    • Cache
      • Engine
    • Configure
    • Console
      • Command
        • Task
    • Controller
      • Component
        • Acl
        • Auth
    • Core
    • Error
    • Event
    • I18n
    • Log
      • Engine
    • Model
      • Behavior
      • Datasource
        • Database
        • Session
      • Validator
    • Network
      • Email
      • Http
    • Routing
      • Filter
      • Route
    • TestSuite
      • Coverage
      • Fixture
      • Reporter
    • Utility
    • View
      • Helper

Classes

  • AclBehavior
  • ContainableBehavior
  • TranslateBehavior
  • TreeBehavior

Class TranslateBehavior

Translate behavior

Object
Extended by ModelBehavior
Extended by TranslateBehavior
Package: Cake\Model\Behavior
Link: http://book.cakephp.org/2.0/en/core-libraries/behaviors/translate.html
Copyright: Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
License: MIT License
Location: Cake/Model/Behavior/TranslateBehavior.php

Properties summary

  • $_joinTable protected
    object
    Stores the joinTable object for generating joins.
  • $_runtimeModel protected
    Model
    Stores the runtime model for generating joins.
  • $runtime public
    array
    Used for runtime configuration of model

Inherited Properties

  • mapMethods, settings

Method Summary

  • _addJoin() protected
    Appends a join for translated fields.
  • _checkConditions() protected

    Check a query's conditions for translated fields. Return an array of translated fields found in the conditions.

  • _getLocale() protected
    Get selected locale for model
  • _prepareTranslations() protected

    Prepares the data to be saved for translated records. Add blank fields, and populates data for multi-locale saves.

  • _removeField() protected
    Update runtime setting for a given field.
  • _setRuntimeData() protected
    Sets the runtime data.
  • afterDelete() public
    afterDelete Callback
  • afterFind() public
    afterFind Callback
  • afterSave() public
    afterSave Callback
  • afterValidate() public

    Restores model data to the original data. This solves issues with saveAssociated and validate = first.

  • beforeFind() public
    beforeFind Callback
  • beforeSave() public
    beforeSave callback.
  • beforeValidate() public
    beforeValidate Callback
  • bindTranslation() public

    Bind translation for fields, optionally with hasMany association for fake field.

  • cleanup() public
    Cleanup Callback unbinds bound translations and deletes setting information.
  • setup() public
    Callback
  • translateModel() public
    Get instance of model for translations.
  • unbindTranslation() public

    Unbind translation for fields, optionally unbinds hasMany association for fake field

Method Detail

_addJoin() protected ¶

_addJoin( Model $Model , array $query , string $field , string $aliasField , string|array $locale )

Appends a join for translated fields.

Parameters
Model $Model
The model being worked on.
array $query
The query array to append a join to.
string $field
The field name being joined.
string $aliasField
The aliased field name being joined.
string|array $locale
The locale(s) having joins added.
Returns
array
The modified query

_checkConditions() protected ¶

_checkConditions( Model $Model , array $query )

Check a query's conditions for translated fields. Return an array of translated fields found in the conditions.

Parameters
Model $Model
The model being read.
array $query
The query array.
Returns
array
The list of translated fields that are in the conditions.

_getLocale() protected ¶

_getLocale( Model $Model )

Get selected locale for model

Parameters
Model $Model
Model the locale needs to be set/get on.
Returns
mixed
string or false

_prepareTranslations() protected ¶

_prepareTranslations( Model $Model , array $data )

Prepares the data to be saved for translated records. Add blank fields, and populates data for multi-locale saves.

Parameters
Model $Model
Model instance
array $data
The sparse data that was provided.
Returns
array
The fully populated data to save.

_removeField() protected ¶

_removeField( Model $Model , string $field )

Update runtime setting for a given field.

Parameters
Model $Model
Model instance
string $field
The field to update.

_setRuntimeData() protected ¶

_setRuntimeData( Model $Model )

Sets the runtime data.

Used from beforeValidate() and beforeSave() for compatibility issues, and to allow translations to be persisted even when validation is disabled.

Parameters
Model $Model

afterDelete() public ¶

afterDelete( Model $Model )

afterDelete Callback

Parameters
Model $Model
Model the callback was run on.
Overrides
ModelBehavior::afterDelete()

afterFind() public ¶

afterFind( Model $Model , array $results , boolean $primary = false )

afterFind Callback

Parameters
Model $Model
Model find was run on
array $results
Array of model results.
boolean $primary optional false
Did the find originate on $model.
Returns
array
Modified results
Overrides
ModelBehavior::afterFind()

afterSave() public ¶

afterSave( Model $Model , boolean $created , array $options = array() )

afterSave Callback

Parameters
Model $Model
Model the callback is called on
boolean $created
Whether or not the save created a record.
array $options optional array()
Options passed from Model::save().
Overrides
ModelBehavior::afterSave()

afterValidate() public ¶

afterValidate( Model $Model )

Restores model data to the original data. This solves issues with saveAssociated and validate = first.

Parameters
Model $Model
Overrides
ModelBehavior::afterValidate()

beforeFind() public ¶

beforeFind( Model $Model , array $query )

beforeFind Callback

Parameters
Model $Model
Model find is being run on.
array $query
Array of Query parameters.
Returns
array
Modified query
Overrides
ModelBehavior::beforeFind()

beforeSave() public ¶

beforeSave( Model $Model , array $options = array() )

beforeSave callback.

Copies data into the runtime property when $options['validate'] is disabled. Or the runtime data hasn't been set yet.

Parameters
Model $Model
Model save was called on.
array $options optional array()
Options passed from Model::save().
Returns
boolean
true.
See
Model::save()
Overrides
ModelBehavior::beforeSave()

beforeValidate() public ¶

beforeValidate( Model $Model , array $options = array() )

beforeValidate Callback

Parameters
Model $Model
Model invalidFields was called on.
array $options optional array()
Options passed from Model::save().
Returns
boolean
See
Model::save()
Overrides
ModelBehavior::beforeValidate()

bindTranslation() public ¶

bindTranslation( Model $Model , string|array $fields , boolean $reset = true )

Bind translation for fields, optionally with hasMany association for fake field.

Note You should avoid binding translations that overlap existing model properties. This can cause un-expected and un-desirable behavior.

Parameters
Model $Model
instance of model
string|array $fields
string with field or array(field1, field2=>AssocName, field3)
boolean $reset optional true

Leave true to have the fields only modified for the next operation. if false the field will be added for all future queries.

Returns
boolean
Throws
CakeException

when attempting to bind a translating called name. This is not allowed as it shadows Model::$name.


cleanup() public ¶

cleanup( Model $Model )

Cleanup Callback unbinds bound translations and deletes setting information.

Parameters
Model $Model
Model being detached.
Overrides
ModelBehavior::cleanup()

setup() public ¶

setup( Model $Model , array $config = array() )

Callback

$config for TranslateBehavior should be array('fields' => array('field_one', 'field_two' => 'FieldAssoc', 'field_three'))

With above example only one permanent hasMany will be joined (for field_two as FieldAssoc)

$config could be empty - and translations configured dynamically by bindTranslation() method

Parameters
Model $Model
Model the behavior is being attached to.
array $config optional array()
Array of configuration information.
Returns
mixed
Overrides
ModelBehavior::setup()

translateModel() public ¶

translateModel( Model $Model )

Get instance of model for translations.

If the model has a translateModel property set, this will be used as the class name to find/use. If no translateModel property is found 'I18nModel' will be used.

Parameters
Model $Model
Model to get a translatemodel for.
Returns
Model

unbindTranslation() public ¶

unbindTranslation( Model $Model , string|array $fields = null )

Unbind translation for fields, optionally unbinds hasMany association for fake field

Parameters
Model $Model
instance of model
string|array $fields optional null

string with field, or array(field1, field2=>AssocName, field3), or null for unbind all original translations

Returns
boolean

Methods inherited from ModelBehavior

_addToWhitelist() protected ¶

_addToWhitelist( Model $model , string $field )

If $model's whitelist property is non-empty, $field will be added to it. Note: this method should only be used in beforeValidate or beforeSave to ensure that it only modifies the whitelist for the current save operation. Also make sure you explicitly set the value of the field which you are allowing.

Parameters
Model $model
Model using this behavior
string $field
Field to be added to $model's whitelist

beforeDelete() public ¶

beforeDelete( Model $model , boolean $cascade = true )

Before delete is called before any delete occurs on the attached model, but after the model's beforeDelete is called. Returning false from a beforeDelete will abort the delete.

Parameters
Model $model
Model using this behavior
boolean $cascade optional true
If true records that depend on this record will also be deleted
Returns
mixed
False if the operation should abort. Any other result will continue.

onError() public ¶

onError( Model $model , string $error )

DataSource error callback

Parameters
Model $model
Model using this behavior
string $error
Error generated in DataSource

Methods inherited from Object

__construct() public ¶

__construct( )

Constructor, no-op

_mergeVars() protected ¶

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

Parameters
array $properties
The name of the properties to merge.
string $class
The class to merge the property with.
boolean $normalize optional true
Set to true to run the properties through Hash::normalize() before merging.

_set() protected ¶

_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() protected ¶

_stop( integer|string $status = 0 )

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

Parameters
integer|string $status optional 0
see http://php.net/exit for values

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_ERR , null|string|array $scope = null )

Convenience 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_ERR
Error type constant. Defined in app/Config/core.php.
null|string|array $scope optional null

The scope(s) a log message is being created in. See CakeLog::config() for more information on logging scopes.

Returns
boolean
Success of log write

requestAction() public ¶

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

Passing POST and GET data

POST and GET data can be simulated in requestAction. Use $extra['url'] for GET data. The $extra['data'] parameter allows POST data simulation.

Parameters
string|array $url

String or array-based URL. Unlike other URL arrays in CakePHP, this URL will not automatically handle passed and named arguments in the $url parameter.

array $extra optional array()

if array includes the key "return" it sets the AutoRender to true. Can also be used to submit GET/POST data, and named/passed arguments.

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

$_joinTable ¶

protected object

Stores the joinTable object for generating joins.

$_runtimeModel ¶

protected Model

Stores the runtime model for generating joins.

$runtime ¶

public array

Used for runtime configuration of model

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