コード例 #1
0
 /**
  * Update address.
  *
  * @param $addressId
  */
 public function showAction($addressId)
 {
     $address = $this->model->getAddress($addressId);
     if (!$address) {
         Router::ErrorResponse('Address not found.', 404);
         return;
     }
     $response = new JsonResponse($address);
     $response->send();
 }
コード例 #2
0
ファイル: Model.php プロジェクト: anzebra/MVC-pattern
 /**
  * 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;
     }
 }