本文整理汇总了PHP中DateTime::attribute_of方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTime::attribute_of方法的具体用法?PHP DateTime::attribute_of怎么用?PHP DateTime::attribute_of使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateTime
的用法示例。
在下文中一共展示了DateTime::attribute_of方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: assign_attribute
/**
* Assign a value to an attribute.
*
* @param string $name Name of the attribute
* @param mixed &$value Value of the attribute
* @return mixed the attribute value
*/
public function assign_attribute($name, $value)
{
$table = static::table();
if (array_key_exists($name, $table->columns) && !is_object($value)) {
$value = $table->columns[$name]->cast($value, static::connection());
}
// convert php's \DateTime to ours
if ($value instanceof \DateTime) {
$value = new DateTime($value->format('Y-m-d H:i:s T'));
}
// make sure DateTime values know what model they belong to so
// dirty stuff works when calling set methods on the DateTime object
if ($value instanceof DateTime) {
$value->attribute_of($this, $name);
}
$this->attributes[$name] = $value;
$this->flag_dirty($name);
return $value;
}
示例2: assign_attribute
/**
* Assign a value to an attribute.
*
* @param string $name Name of the attribute
* @param mixed &$value Value of the attribute
* @return mixed the attribute value
*/
public function assign_attribute($name, $value)
{
$table = static::table();
if (!is_object($value)) {
if (array_key_exists($name, $table->columns)) {
$value = $table->columns[$name]->cast($value, static::connection());
} else {
$col = $table->get_column_by_inflected_name($name);
if (!is_null($col)) {
$value = $col->cast($value, static::connection());
}
}
}
// convert php's \DateTime to ours
if ($value instanceof \DateTime) {
// $value = new DateTime($value->format('Y-m-d H:i:s T'));
//== My change ==//
$value = new DateTime($value->format(Config::instance()->get_date_format()));
//== End my change ==//
}
// make sure DateTime values know what model they belong to so
// dirty stuff works when calling set methods on the DateTime object
if ($value instanceof DateTime) {
$value->attribute_of($this, $name);
}
$this->attributes[$name] = $value;
$this->flag_dirty($name);
return $value;
}