Raw.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. use Yaf\Controller_Abstract as AbstractController;
  3. class RawController extends AbstractController
  4. {
  5. public function jsonAction ()
  6. {
  7. header('Content-type: application/json');
  8. die(json_encode(array('message' => 'Hello World!')));
  9. }
  10. public function dbAction ()
  11. {
  12. $dbh = DatabaseManager::getInstance()->getConnection();
  13. $query_count = (int) $this->getRequest()->get('queries', 1);
  14. if (0 >= $query_count) {
  15. $query_count = 1;
  16. } elseif (500 < $query_count) {
  17. $query_count = 500;
  18. }
  19. $arr = array();
  20. $id = mt_rand(1, 10000);
  21. $statement = $dbh->prepare('SELECT `randomNumber` FROM `World` WHERE `id` = :id');
  22. $statement->bindParam(':id', $id, \PDO::PARAM_INT);
  23. while (0 < $query_count--) {
  24. $statement->execute();
  25. $arr[] = array('id' => $id, 'randomNumber' => $statement->fetchColumn());
  26. $id = mt_rand(1, 10000);
  27. }
  28. header('Content-type: application/json');
  29. die(json_encode($arr));
  30. }
  31. public function fortunesAction ()
  32. {
  33. $view = $this->getView();
  34. /* @var $view eYaf\Layout */
  35. $view->setLayout('fortunes');
  36. $dbh = DatabaseManager::getInstance()->getConnection();
  37. $statement = $dbh->query('SELECT `id`, `message` FROM `Fortune`');
  38. $arr = $statement->fetchAll(\PDO::FETCH_KEY_PAIR);
  39. $arr[0] = 'Additional fortune added at request time.';
  40. asort($arr);
  41. $view->rows = $arr;
  42. header('Content-Type: text/html; charset=utf-8');
  43. }
  44. }