本文整理匯總了PHP中fORM::replicate方法的典型用法代碼示例。如果您正苦於以下問題:PHP fORM::replicate方法的具體用法?PHP fORM::replicate怎麽用?PHP fORM::replicate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類fORM
的用法示例。
在下文中一共展示了fORM::replicate方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: __clone
/**
* Creates a clone of a record
*
* If the record has an auto incrementing primary key, the primary key will
* be erased in the clone. If the primary key is not auto incrementing,
* the primary key will be left as-is in the clone. In either situation the
* clone will return `FALSE` from the ::exists() method until ::store() is
* called.
*
* @internal
*
* @return fActiveRecord
*/
public function __clone()
{
$class = get_class($this);
// Copy values and cache, making sure objects are cloned to prevent reference issues
$temp_values = $this->values;
$new_values = array();
$this->values =& $new_values;
foreach ($temp_values as $column => $value) {
$this->values[$column] = fORM::replicate($class, $column, $value);
}
$temp_cache = $this->cache;
$new_cache = array();
$this->cache =& $new_cache;
foreach ($temp_cache as $key => $value) {
if (is_object($value)) {
$this->cache[$key] = clone $value;
} else {
$this->cache[$key] = $value;
}
}
// Related records are purged
$new_related_records = array();
$this->related_records =& $new_related_records;
// Old values are changed to look like the record is non-existant
$new_old_values = array();
$this->old_values =& $new_old_values;
foreach (array_keys($this->values) as $key) {
$this->old_values[$key] = array(NULL);
}
// If we have a single auto incrementing primary key, remove the value
$schema = fORMSchema::retrieve($class);
$table = fORM::tablize($class);
$pk_columns = $schema->getKeys($table, 'primary');
if (sizeof($pk_columns) == 1 && $schema->getColumnInfo($table, $pk_columns[0], 'auto_increment')) {
$this->values[$pk_columns[0]] = NULL;
unset($this->old_values[$pk_columns[0]]);
}
}