當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DateTime::attribute_of方法代碼示例

本文整理匯總了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;
 }
開發者ID:neoff,項目名稱:mywork,代碼行數:26,代碼來源:Model.php

示例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;
 }
開發者ID:bsa-git,項目名稱:silex-mvc,代碼行數:36,代碼來源:Model.php


注:本文中的DateTime::attribute_of方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。