Пример #1
0
 /**
  * Create new model
  *
  * <code>
  * $post = new BloPost;
  *
  * $post = new BloPost([
  *     'title' => 'Hello',
  *     'body' => 'World!'
  * ]);
  * </code>
  *
  * **NOTE:** This method does not save anything to database
  *
  * - New model is not saved to the database and has $this->isNewRecord() == true
  * - If $attrs has **'id'** key then model with the same id will be loaded from
  *   the database and its attributes will be overwritten (but not saved)
  *
  * @param array $attrs Associative array representing new model properies
  */
 public function __construct($attrs = null)
 {
     parent::__construct();
     $this->className = get_class($this);
     if (!$this->table) {
         $this->table = $this->classNameToTableName($this->className);
     }
     $this->makeReflection();
     $this->isDeletedRecord = false;
     $this->checkAssociationClasses();
     $this->associationsCache = [];
     if ($attrs) {
         if (array_key_exists('id', $attrs)) {
             $this->id = $attrs["id"];
             $this->reload();
         }
         foreach ($attrs as $name => $value) {
             if (!in_array($name, $this->attributes)) {
                 throw new TipyModelException("Unknown property '" . $name . "' for " . $this->className);
             }
             $this->data[$name] = $value;
         }
     }
 }