Translate behavior
$_joinTable
protected object
$_runtimeModel
protected $runtime
public array
Check a query's conditions for translated fields. Return an array of translated fields found in the conditions.
Prepares the data to be saved for translated records. Add blank fields, and populates data for multi-locale saves.
Restores model data to the original data. This solves issues with saveAssociated and validate = first.
Bind translation for fields, optionally with hasMany association for fake field.
Unbind translation for fields, optionally unbinds hasMany association for fake field
_addJoin( Model $Model , array $query , string $field , string $aliasField , string|array $locale )
Appends a join for translated fields.
Model
$Model
$query
$field
$aliasField
$locale
_checkConditions( Model $Model , array $query )
Check a query's conditions for translated fields. Return an array of translated fields found in the conditions.
Model
$Model
$query
_getLocale( Model $Model )
Get selected locale for model
Model
$Model
_prepareTranslations( Model $Model , array $data )
Prepares the data to be saved for translated records. Add blank fields, and populates data for multi-locale saves.
Model
$Model
$data
_removeField( Model $Model , string $field )
Update runtime setting for a given field.
Model
$Model
$field
_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.
Model
$Model
afterDelete( Model $Model )
afterDelete Callback
Model
$Model
ModelBehavior::afterDelete()
afterFind( Model $Model , array $results , boolean $primary false )
afterFind Callback
Model
$Model
$results
$primary
optional false ModelBehavior::afterFind()
afterSave( Model $Model , boolean $created , array $options array() )
afterSave Callback
Model
$Model
$created
$options
optional array() ModelBehavior::afterSave()
afterValidate( Model $Model )
Restores model data to the original data. This solves issues with saveAssociated and validate = first.
Model
$Model
ModelBehavior::afterValidate()
beforeFind( Model $Model , array $query )
beforeFind Callback
Model
$Model
$query
ModelBehavior::beforeFind()
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.
Model
$Model
$options
optional array() ModelBehavior::beforeSave()
beforeValidate( Model $Model , array $options array() )
beforeValidate Callback
Model
$Model
$options
optional array() ModelBehavior::beforeValidate()
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.
Model
$Model
$fields
$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.
CakeException
when attempting to bind a translating called name. This is not allowed as it shadows Model::$name.
cleanup( Model $Model )
Cleanup Callback unbinds bound translations and deletes setting information.
Model
$Model
ModelBehavior::cleanup()
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
Model
$Model
$config
optional array() ModelBehavior::setup()
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.
Model
$Model
Model
unbindTranslation( Model $Model , string|array $fields null )
Unbind translation for fields, optionally unbinds hasMany association for fake field
Model
$Model
$fields
optional null string with field, or array(field1, field2=>AssocName, field3), or null for unbind all original translations
_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.
Model
$model
$field
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.
Model
$model
$cascade
optional true onError( Model $model , string $error )
DataSource error callback
Model
$model
$error
_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() 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.
$msg
$type
optional LOG_ERR $scope
optional null The scope(s) a log message is being created in. See CakeLog::config() for more information on logging scopes.
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()
POST and GET data can be simulated in requestAction. Use $extra['url']
for GET data. The $extra['data']
parameter allows POST data simulation.
$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.
$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.
Boolean true or false on success/failure, or contents of rendered action if 'return' is set in $extra.
toString( )
Object-to-string conversion. Each class can override this method as necessary.
© 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.8/class-TranslateBehavior.html