ExampleTool.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. Lib::loadClass('RouteToolBase');
  3. Lib::loadClass('UI');
  4. Lib::loadClass('Response');
  5. Lib::loadClass('Theme');
  6. // class name must have the same name as file
  7. // index.php?_route=UrlAction_BraveCare - uruchamia defaultAction
  8. class ExampleTool extends RouteToolBase {
  9. public function defaultAction() {
  10. UI::gora();
  11. Theme::top();
  12. echo '<h1>Example Tool</h1>';
  13. UI::inlineJS(__FILE__ . '.example.js', [
  14. 'URL_TEST_AJAX_ACTION' => $this->getLink('testAjax'),
  15. ]);
  16. UI::dol();
  17. }
  18. public function testAjaxAction() {
  19. Response::sendTryCatchJson(array($this, 'testAjax'), $_REQUEST); // args from request
  20. // Response::sendTryCatchJson(array($this, 'testAjax'), $args = 'JSON_FROM_REQUEST_BODY'); // args from json request
  21. }
  22. public function testAjax($args) { // args given by sendTryCatchJson
  23. $items = [
  24. [ 'ID' => 1, 'name' => 'x', 'desc' => 'a' ],
  25. [ 'ID' => 2, 'name' => 'y', 'desc' => 'b' ],
  26. [ 'ID' => 3, 'name' => 'z', 'desc' => 'c' ],
  27. ];
  28. return [
  29. 'type' => 'success',
  30. 'msg' => 'OK',
  31. 'body' => [
  32. 'items' => $items,
  33. ]
  34. ];
  35. }
  36. }