ku_controller.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. class KuController extends AppController
  3. {
  4. protected function before_filter()
  5. {
  6. View::select(null, null);
  7. header('Content-Type: application/json');
  8. }
  9. public function index()
  10. {
  11. KuRaw::$random->execute([mt_rand(1, 10000)]);
  12. echo json_encode(KuRaw::$random->fetch());
  13. }
  14. public function query($count = 1)
  15. {
  16. $count = min(max((int) $count, 1), 500);
  17. $random = KuRaw::$random;
  18. while ($count--) {
  19. $random->execute([mt_rand(1, 10000)]);
  20. $worlds[] = $random->fetch();
  21. }
  22. echo json_encode($worlds);
  23. }
  24. public function update($count = 1)
  25. {
  26. $count = min(max((int) $count, 1), 500);
  27. $random = KuRaw::$random;
  28. while ($count--) {
  29. $random->execute([mt_rand(1, 10000)]);
  30. $row = $random->fetch();
  31. $row['randomNumber'] = mt_rand(1, 10000);
  32. $worlds[] = $row;
  33. }
  34. KuRaw::update($worlds);
  35. echo json_encode($worlds);
  36. }
  37. }