Advertisement
Guest User

Untitled

a guest
Nov 19th, 2015
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.40 KB | None | 0 0
  1. <?php
  2. require_once('config.php');
  3. $f3 = require_once('lib/base.php');
  4.  
  5. class cookingAPI {
  6.  
  7.     private $db = new DB\SQL(
  8.         'mysql:host='.DB_HOST.';port=3306;dbname='.DB_NAME,
  9.         DB_USER,
  10.         DB_PASS
  11.         );
  12.     private $user = new DB\SQL\Mapper($db,'users');
  13.     private $recipe = new DB\SQL\Mapper($db,'recipes');
  14.     private $ingredient = new DB\SQL\Mapper($db,'ingredients');
  15.  
  16.     $f3->set('DB', $db);
  17.     $f3->route('GET /',
  18.             function() {
  19.                 echo 'Hello, World!';
  20.             }
  21.         );
  22.     $f3->route('GET /user',
  23.             function() {
  24.                 echo 'All users';
  25.             }
  26.         );
  27.     $f3->route('GET /user/@id',
  28.             function($f3) {
  29.                 echo 'user #'.$f3->get('PARAMS.id');
  30.             }
  31.         );
  32.     $f3->route('GET /recipe',
  33.             function() {
  34.                 echo 'All recipes';
  35.             }
  36.         );
  37.     $f3->route('GET /recipe/@id',
  38.             function($f3) {
  39.                 echo 'Recipe #'.$f3->get('PARAMS.id');
  40.             }
  41.         );
  42.     $f3->route('GET /ingredient',
  43.             function() {
  44.                 echo 'All ingredients';
  45.             }
  46.         );
  47.     $f3->route('GET /ingredient',
  48.             function($f3) {
  49.                 echo 'Ingredient #'.$f3->get('PARAMS.id');
  50.             }
  51.         );
  52.  
  53.     function __construct() {
  54.         $f3->run();
  55.        
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement