Class CTimestampBehavior
CTimestampBehavior will automatically fill date and time related attributes.
CTimestampBehavior will automatically fill date and time related attributes when the active record is created and/or updated. You may specify an active record model to use this behavior like so:
public function behaviors(){ return array( 'CTimestampBehavior' => array( 'class' => 'zii.behaviors.CTimestampBehavior', 'createAttribute' => 'create_time_attribute', 'updateAttribute' => 'update_time_attribute', ) ); }
The CTimestampBehavior::$createAttribute
and CTimestampBehavior::$updateAttribute
options actually
default to 'create_time' and 'update_time' respectively, so it is not required
that you configure them. If you do not wish CTimestampBehavior to set a
timestamp for record update or creation, set the corresponding attribute option
to null.
By default, the update attribute is only set on record update. If you also
wish it to be set on record creation, set the CTimestampBehavior::$setUpdateOnCreate
option
to true.
Although CTimestampBehavior attempts to figure out on it's own what value to
inject into the timestamp attribute, you may specify a custom value to use
instead via CTimestampBehavior::$timestampExpression
- CComponent
- CBehavior implements IBehavior
- CModelBehavior
- CActiveRecordBehavior
- CTimestampBehavior
Copyright: 2008-2013 Yii Software LLC
License: http://www.yiiframework.com/license/
Author: Jonah Turnquist <poppitypop@gmail.com>
Since: 1.1
Located at x2engine/framework/zii/behaviors/CTimestampBehavior.php
public
|
#
beforeSave(
Responds to CModel::onBeforeSave event. Sets the values of the creation or modified attributes as configured |
protected
mixed
|
#
getTimestampByAttribute( string $attribute )
Gets the appropriate timestamp depending on the column type $attribute is |
protected
mixed
|
#
getTimestampByColumnType( string $columnType )
Returns the appropriate timestamp depending on $columnType |
afterDelete(),
afterFind(),
afterSave(),
beforeCount(),
beforeDelete(),
beforeFind(),
events()
|
afterConstruct(),
afterValidate(),
beforeValidate()
|
attach(),
detach(),
getEnabled(),
getOwner(),
setEnabled()
|
public
mixed
|
$createAttribute | 'create_time' |
#
The name of the attribute to store the creation time. Set to null to not use a timestamp for the creation attribute. Defaults to 'create_time' |
public
mixed
|
$updateAttribute | 'update_time' |
#
The name of the attribute to store the modification time. Set to null to not use a timestamp for the update attribute. Defaults to 'update_time' |
public
boolean
|
$setUpdateOnCreate | false |
#
Whether to set the update attribute to the creation timestamp upon creation. Otherwise it will be left alone. Defaults to false. |
public
mixed
|
$timestampExpression |
|
#
The expression that will be used for generating the timestamp. This can be
either a string representing a PHP expression (e.g. 'time()'), or a A PHP expression can be any PHP code that has a value. To learn more about what an expression is, please refer to the php manual. |
protected static
array
|
$map | array(
'datetime'=>'NOW()',
'timestamp'=>'NOW()',
'date'=>'NOW()',
) |
#
Maps column types to database method |
$owner
|
$enabled
|