Advertisement
Guest User

route.php

a guest
Mar 23rd, 2017
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.20 KB | None | 0 0
  1. <?php
  2. // Routes
  3.  
  4. $app->get('/', function ($request, $response, $args) {
  5.     // Sample log message
  6.     $this->logger->info("Slim-Skeleton '/' route");
  7.  
  8.     // Render index view
  9.     return $this->renderer->render($response, 'index.phtml', $args);
  10. });
  11.  
  12. $app->get('/get-data', function($request, $response, $args){
  13.     return Account::all()->toJson();
  14. });
  15.  
  16. $app->post('/insert-data', function($request, $response, $args){
  17.     $input = $request->getParsedBody();
  18.     $account = new Account;
  19.     $account->id = $input['id'];
  20.     $account->username = $input['username'];
  21.     $account->email = $input['email'];
  22.     $account->password = $input['password'];
  23.     $account->save();
  24.  
  25.     return $account->toJson();
  26. });
  27.  
  28. $app->put('/update-data', function($request, $response, $args){
  29.     $input = $request->getParsedBody();
  30.     $find = Account::where('id', '=', $input['id'])->first();
  31.     $find->username = $input['username'];
  32.     $find->email = $input['email'];
  33.     $find->password = $input['password'];
  34.     $find->save();
  35.  
  36.     return $find->toJson();
  37. });
  38.  
  39. $app->delete('/delete-data', function($request, $response, $args){
  40.     $input = $request->getParsedBody();
  41.     $find = Account::where('id', '=', $input['id'])->first();
  42.     $find->delete();
  43. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement