TranslateBehavior Class Info:
- Class Declaration:
class TranslateBehavior extends ModelBehavior
- File name:
- cake/libs/model/behaviors/translate.php
- Description:
Translate behavior
- Class Inheritance
- Package
- cake
- Subpackage
- cake.cake.libs.model.behaviors
- Link
- http://book.cakephp.org/view/1328/Translate
Properties:
-
mapMethods array
Allows the mapping of preg-compatible regular expressions to public or private methods in this class, where the array key is a /-delimited regular expression, and the value is a class method. Similar to the functionality of the findBy* / findAllBy* magic methods.
-
runtime array
Used for runtime configuration of model
-
settings array
Contains configuration settings for use with individual model objects. This is used because if multiple models use this Behavior, each will use the same object instance. Individual model settings should be stored as an associative array, keyed off of the model name.
Method Summary:
- _addToWhitelist( $model, $field )
- afterDelete( $model )
- afterFind( $model, $results, $primary )
- afterSave( $model, $created )
- beforeDelete( $model, $cascade = true )
- beforeFind( $model, $query )
- beforeSave( $model )
- beforeValidate( $model )
- bindTranslation( $model, $fields, $reset = true )
- cakeError( $method, $messages = array ( ) )
- cleanup( $model )
- __construct( )
- dispatchMethod( $model, $method, $params = array ( ) )
- _getLocale( $model )
- log( $msg, $type = 2 )
- Object( )
- onError( $model, $error )
- _persist( $name, $return, $object, $type = NULL )
- requestAction( $url, $extra = array ( ) )
- _savePersistent( $name, $object )
- _set( $properties = array ( ) )
- setup( $model, $config = array ( ) )
- _stop( $status = 0 )
- toString( )
- translateModel( $model )
- unbindTranslation( $model, $fields = NULL )
_addToWhitelist
topIf $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:
-
-
object $model required
Model using this behavior
-
string $field required
Field to be added to $model's whitelist
-
- Method defined in:
- cake/libs/model/model_behavior.php on line 196
- Access
protected
- Return
void
afterDelete
topafterDelete Callback
- Parameters:
-
-
Model $model required
Model the callback was run on.
-
- Method defined in:
- cake/libs/model/behaviors/translate.php on line 342
- Return
void
- Access
public
afterFind
topafterFind Callback
- Parameters:
-
-
Model $model required
Model find was run on
-
array $results required
Array of model results.
-
boolean $primary required
Did the find originate on $model.
-
- Method defined in:
- cake/libs/model/behaviors/translate.php on line 219
- Return
array Modified results
- Access
public
afterSave
topafterSave Callback
- Parameters:
-
-
Model $model required
Model the callback is called on
-
boolean $created required
Whether or not the save created a record.
-
- Method defined in:
- cake/libs/model/behaviors/translate.php on line 298
- Return
void
- Access
public
beforeDelete
topBefore delete callback
- Parameters:
-
-
object $model required
Model using this behavior
-
boolean $cascade optional true
If true records that depend on this record will also be deleted
-
- Method defined in:
- cake/libs/model/model_behavior.php on line 135
- Return
mixed False if the operation should abort. Any other result will continue.
- Access
public
beforeFind
topbeforeFind Callback
- Parameters:
-
-
Model $model required
Model find is being run on.
-
array $query required
Array of Query parameters.
-
- Method defined in:
- cake/libs/model/behaviors/translate.php on line 92
- Return
array Modified query
- Access
public
beforeSave
topBefore save callback
- Parameters:
-
-
object $model required
Model using this behavior
-
- Method defined in:
- cake/libs/model/model_behavior.php on line 116
- Return
mixed False if the operation should abort. Any other result will continue.
- Access
public
beforeValidate
topbeforeValidate Callback
- Parameters:
-
-
Model $model required
Model invalidFields was called on.
-
- Method defined in:
- cake/libs/model/behaviors/translate.php on line 263
- Return
boolean
- Access
public
bindTranslation
topBind translation for fields, optionally with hasMany association for fake field
- Parameters:
-
-
$model required
-
$fields required
-
boolean $reset optional true
with field or array(field1, field2=>AssocName, field3)
-
- Method defined in:
- cake/libs/model/behaviors/translate.php on line 410
- Return
bool
cakeError
topUsed 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 required
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
-
- Method defined in:
- cake/libs/object.php on line 187
- Return
error message
- Access
public
cleanup
topCleanup Callback unbinds bound translations and deletes setting information.
- Parameters:
-
-
Model $model required
Model being detached.
-
- Method defined in:
- cake/libs/model/behaviors/translate.php on line 78
- Return
void
- Access
public
__construct
topClass constructor, overridden in descendant classes.
- Method defined in:
- cake/libs/object.php on line 54
dispatchMethod
topOverrides Object::dispatchMethod to account for PHP4's broken reference support
- Parameters:
-
-
$model required
-
$method required
-
$params optional array ( )
-
- Method defined in:
- cake/libs/model/model_behavior.php on line 161
- See
Object::dispatchMethod
- Access
public
- Return
mixed
_getLocale
topGet selected locale for model
- Parameters:
-
-
Model $model required
Model the locale needs to be set/get on.
-
- Method defined in:
- cake/libs/model/behaviors/translate.php on line 355
- Return
mixed string or false
- Access
protected
log
topConvience method to write a message to CakeLog. See CakeLog::write() for more information on writing to logs.
- Parameters:
-
-
string $msg required
Log message
-
integer $type optional 2
Error type constant. Defined in app/config/core.php.
-
- Method defined in:
- cake/libs/object.php on line 148
- Return
boolean Success of log write
- Access
public
Object
topA 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:
- cake/libs/object.php on line 43
- Return
Object
onError
topDataSource error callback
- Parameters:
-
-
object $model required
Model using this behavior
-
string $error required
Error generated in DataSource
-
- Method defined in:
- cake/libs/model/model_behavior.php on line 152
- Access
public
_persist
topChecks 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 required
name of the class to persist
-
$return required
-
string $object required
the object to persist
-
$type optional NULL
-
- Method defined in:
- cake/libs/object.php on line 218
- Return
boolean Success
- Access
protected
- Todo
add examples to manual
requestAction
topCalls 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 required
String or array-based url.
-
array $extra optional array ( )
if array includes the key "return" it sets the AutoRender to true.
-
- Method defined in:
- cake/libs/object.php on line 80
- Return
mixed Boolean true or false on success/failure, or contents of rendered action if 'return' is set in $extra.
- Access
public
_savePersistent
topYou should choose a unique name for the persistent file
There are many uses for this method, see manual for examples
- Parameters:
-
-
string $name required
name used for object to cache
-
object $object required
the object to persist
-
- Method defined in:
- cake/libs/object.php on line 247
- Return
boolean true on save, throws error if file can not be created
- Access
protected
_set
topAllows 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.
-
- Method defined in:
- cake/libs/object.php on line 166
- Return
void
- Access
protected
setup
topCallback
$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 required
Model the behavior is being attached to.
-
array $config optional array ( )
Array of configuration information.
-
- Method defined in:
- cake/libs/model/behaviors/translate.php on line 55
- Return
mixed
- Access
public
_stop
topStop execution of the current script. Wraps exit() making testing easier.
- Parameters:
-
-
$status optional 0
-
- Method defined in:
- cake/libs/object.php on line 135
- Return
void
- Access
public
toString
topObject-to-string conversion. Each class can override this method as necessary.
- Method defined in:
- cake/libs/object.php on line 64
- Return
string The name of this class
- Access
public
translateModel
topGet 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 required
Model to get a translatemodel for.
-
- Method defined in:
- cake/libs/model/behaviors/translate.php on line 378
- Return
object
- Access
public
unbindTranslation
topUnbind translation for fields, optionally unbinds hasMany association for fake field
- Parameters:
-
-
object $model required
instance of model
-
mixed $fields optional NULL
string with field, or array(field1, field2=>AssocName, field3), or null for unbind all original translations
-
- Method defined in:
- cake/libs/model/behaviors/translate.php on line 483
- Return
bool