index.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace controller;
  3. class index extends \Qii\Base\Controller
  4. {
  5. public $enableDB = true;
  6. public $enableView = true;
  7. public function indexAction()
  8. {
  9. $html = [];
  10. $html[] = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>示例程序</title><style>ul{list-style:none;}</style></head><body>';
  11. $html[] = '<ul>示例程序';
  12. $html[] = '<li>><a href="'. _link('dirs.html') .'">文件管理</a></li>';
  13. $html[] = '<li>><a href="'. _link('database/creator.html') .'">数据表管理</a></li>';
  14. $html[] = '<li>><a href="'. _link('index/dispatch.html') .'">Dispatch</a></li>';
  15. $html[] = '<li>><a href="'. _link('index/forward.html') .'">Forward</a></li>';
  16. $html[] = '<li>><a href="'. _link('index/display.html') .'">使用指定目录中的模板</a></li>';
  17. $html[] = '</ul>';
  18. $html[] = '</body></html>';
  19. return $this->setResponse(new \Qii\Base\Response(array('format' => 'html', 'body' => join("\n", $html))));
  20. return;
  21. $data = array();
  22. $data['lists'][] = $this->db->getRow('SELECT * FROM ipAddress ORDER BY id DESC LIMIT 1');
  23. $data['lists'][] = $this->db->getRow('SELECT * FROM ipAddress ORDER BY id ASC LIMIT 1');
  24. $data['querySeconds'] = $this->db->querySeconds;
  25. return new \Qii\Base\Response(array('format' => 'json', 'body' => $data));
  26. }
  27. /**
  28. * 设置controller中间件,此中间件将会在controller初始化之前使用
  29. * @return array
  30. */
  31. public function getMiddleware()
  32. {
  33. return parent::getMiddleware(); // TODO: Change the autogenerated stub
  34. }
  35. public function dispatchAction()
  36. {
  37. echo "<p>Dispatch start ". __CLASS__ ."</p>";
  38. $this->dispatch('test', 'index');
  39. echo "<p>Dispatch end ". __CLASS__ ."</p>";
  40. }
  41. public function forwardAction()
  42. {
  43. echo "<p>This is start section " . __CLASS__ . " Forward</p>";
  44. $this->setForward('test', 'index');
  45. echo "<p>This is end section " . __CLASS__ . " Forward</p>";
  46. }
  47. public function displayAction()
  48. {
  49. //可以从这里设置加载模板的路径
  50. $this->view->setTemplateDir(__DIR__ . "/view/");
  51. echo $this->view->fetch('index.tpl');
  52. }
  53. }