Ejemplo n.º 1
0
 /**
  * Update model.
  *
  * @param int $id
  * @return bool
  */
 public function update($id)
 {
     $keys = array_keys($this->attributesValues);
     $preparedKeys = array_map(function ($key) {
         return $key . '=:' . $key;
     }, $keys);
     $preparedKeysString = implode(', ', $preparedKeys);
     $this->attributesValues[$this->primaryKey] = (int) $id;
     try {
         $query = $this->db->prepare('UPDATE ' . $this->table . ' SET ' . $preparedKeysString . ' ' . ' WHERE ' . $this->primaryKey . ' = :' . $this->primaryKey);
         $query->execute($this->attributesValues);
     } catch (PDOException $e) {
         Router::ErrorResponse('Invalid request.');
         die;
     }
 }