[Li Jingshan php] every day tp5-20170109|thinkphp5-model.php-2

Source: Internet
Author: User

    /**     *  set data Object values      * @ access public     *  @param  mixed  $data   Data or attribute names       *  @param  mixed  $value   values      *  @return   $this      */    public function data ($data,  $value  = null)     {//  set data Object values          if  (is_string ($data))  {// is_string ($data)               $this->data[$data] =  $value;//  enables the  key value of the data   Assignment         } else {             //  Clear Data               $this->data = [];//  non-string   first   empty   data              if  (Is_object ($data))  {//  if object                   $data  = get_object_vars ($data);//  Gets the value of the object              }             if  (true ===  $value)  {//  if  value   true                 //  assigning values to data Objects                 foreach  ( $data  as  $key  =>  $value)  {//  data Object Assignment                       $this->setattr ($key,  $ value,  $data);                 }             } else {//  By default, you're talking about arrays.,                  $this->data  =  $data;            }         }        return  $this;//  Implementation coherence   Operation     }//  Lao Liu   your team   getting weaker, this version   is not as good as the  3.2  version of this function      /**     * 3.2  version of,  you can compare       *  set data Object values      *  @access  public      *  @param  mixed  $data   data      *  @return  Model      *///    public function data ($data = ") {//         if ('  ===  $data  && !empty ($this->data)  {//             return  $this->data;//         }//        if (Is_object ($data)) {//              $data    =   get_object_ VARs ($data);//        }elseif (Is_string ($data)) {//             parse_str ($data, $data);//         }elseif (!is_array ($data)) {//             e (L (' _data_type_invalid_ '));//        }//          $this->data =  $data;//        return  $this;//     }    /**     *  Get object raw data   Returns false     *  if the specified field does not exist @access  public     * @ param string  $name   Field name   leave blank get all      *  @return  mixed      *  @throws  InvalidArgumentException     */     public function getdata ($name  = null)     {//  Added   Get Data function, the previous function   do   Division         //  return all   with   Return key        if  (Is_null ($name))  {             return  $this->data;         } elseif  (array_key_exists ($name,  $this->data)  {             return  $this->data[$name];        }  else {            throw new  InvalidArgumentException (' property not exists: '  .  $this->class .  ')  .  $name);        }    }     /**     *  modifiers   Set data object values      * @ access public     *  @param  string     $name   Property names      *  @param  mixed      $value   Property values       *  @param  array      $data   Data       *  @return  $This     */    public function setattr ($name,  $ value,  $data  = [])     {//  modifier   Set data Object values          if  (Is_null ($value)  &&  $this->autowritetimestamp & & in_array ($name,  [$this->createtime,  $this->updatetime])  {             //  Auto-write timestamp fields               $value  =  $this->autowritetimestamp ($name);//  write time          } else {             //  detection modifier             $ method =  ' Set '  . loader::p arsename ($name,  1)  .  ' Attr ';//  has a special   The processing function for this property             if  (method_exists ($this,  $method))  {//   Set the current property                 $ value =  $this $method ($value,  array_merge ($data,  $this->data));             } elseif  (Isset ($this->type[$name])  {                 //  type Conversion                  $value  =   $this->writetransform ($value,  $this->type[$name]);//write data type conversion              }        }         //  Mark Field Changes         if  (!isset ($ this->data[$name]) | |   ($this->data[$name] !=  $value  && !in_array ($name,  $this->change)) )  {             $this->change[] =   $name;//  marker fields   Change         }         //  set data Object Properties          $this->data[$name]  =  $value;//  settings   Data Objects   Properties         return $ this;    }


This article is from the "Focus on PHP Group number: 414194301" blog, please be sure to keep this source http://jingshanls.blog.51cto.com/3357095/1879826

[Li Jingshan php] every day tp5-20170109|thinkphp5-model.php-2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.