Guest User

Untitled

a guest
Nov 18th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. class Api_Controller extends Controller {
  2.  
  3. /**
  4. * Starting point
  5. */
  6. public function index()
  7. {
  8. // Disables CSRF validation for API requests
  9. Validation::$is_api_request = TRUE;
  10.  
  11. // Instantiate the API service
  12. $api_service = new Api_Service();
  13.  
  14. // Run the service
  15. $api_service->run_service();
  16.  
  17. // Avoid caching
  18. header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
  19. header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
  20.  
  21. $callback = '';
  22. $resp = "";
  23. if ($api_service->get_response_type() == 'jsonp')
  24. {
  25. header("Content-type: application/json; charset=utf-8");
  26. $resp = $callback.'('.$api_service->get_response().')';
  27. }
  28. elseif ($api_service->get_response_type() == 'xml')
  29. {
  30. header("Content-type: text/xml");
  31. $resp = $api_service->get_response();
  32. }
  33. else
  34. {
  35. header("Content-type: application/json; charset=utf-8");
  36. $resp = $api_service->get_response();
  37. }
  38.  
  39. print $resp;
  40.  
  41. }
  42. }
Add Comment
Please, Sign In to add comment