Exemplo n.º 1
0
 public function delete($id)
 {
     try {
         //fetch the entity
         $entity = $this->gateway->findByPk($id);
         if (!$entity) {
             return $this->payload->notFound(['id' => $id]);
         }
         //delete the entity
         if (!$this->gateway->delete($entity)) {
             return $this->payload->notDeleted([$this->entityName => $entity]);
         }
         //success
         return $this->payload->deleted([$this->entityName => $entity]);
     } catch (\Exception $e) {
         return $this->payload->error(['exception' => $e, $this->entityName => $entity]);
     }
 }
Exemplo n.º 2
0
<?php

/**
 * Copyright (c) 2014 Keith Casey.
 *
 * This code is designed to accompany the lynda.com video course "Design Patterns in PHP"
 *   by Keith Casey. If you've received this code without seeing the videos, go watch the
 *   videos. It will make way more sense and be more useful in general.
 */
include_once 'user.php';
$gateway = new UserGateway();
$users = $gateway->loadAll();
foreach ($users as $user) {
    echo $user['user_username'] . '<br />';
}
echo '<hr />';
$user = $gateway->loadById(2);
echo $user['user_username'];
Exemplo n.º 3
0
<?php

/**
 * Copyright (c) 2014 Keith Casey.
 *
 * This code is designed to accompany the lynda.com video course "Design Patterns in PHP"
 *   by Keith Casey. If you've received this code without seeing the videos, go watch the
 *   videos. It will make way more sense and be more useful in general.
 */
require 'vendor/autoload.php';
include_once 'user.php';
$gateway = new UserGateway();
$users = $gateway->select();
foreach ($users as $user) {
    echo $user['user_username'] . '<br />';
}
echo '<hr />';
$users = $gateway->select(array('user_id' => 2));
foreach ($users as $user) {
    echo $user['user_username'] . '<br />';
}