index.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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('index/dispatch.html') .'">Dispatch</a></li>';
  14. $html[] = '<li>><a href="'. _link('index/forward.html') .'">Forward</a></li>';
  15. $html[] = '<li>><a href="'. _link('index/display.html') .'">使用指定目录中的模板</a></li>';
  16. $html[] = '</ul>';
  17. $html[] = '</body></html>';
  18. return $this->setResponse(new \Qii\Base\Response(array('format' => 'html', 'body' => join("\n", $html))));
  19. return;
  20. $data = array();
  21. $data['lists'][] = $this->db->getRow('SELECT * FROM ipAddress ORDER BY id DESC LIMIT 1');
  22. $data['lists'][] = $this->db->getRow('SELECT * FROM ipAddress ORDER BY id ASC LIMIT 1');
  23. $data['querySeconds'] = $this->db->querySeconds;
  24. return new \Qii\Base\Response(array('format' => 'json', 'body' => $data));
  25. }
  26. public function dispatchAction()
  27. {
  28. echo "<p>Dispatch start ". __CLASS__ ."</p>";
  29. $this->dispatch('test', 'index');
  30. echo "<p>Dispatch end ". __CLASS__ ."</p>";
  31. }
  32. public function forwardAction()
  33. {
  34. echo "<p>This is start section " . __CLASS__ . " Forward</p>";
  35. $this->setForward('test', 'index');
  36. echo "<p>This is end section " . __CLASS__ . " Forward</p>";
  37. }
  38. public function displayAction()
  39. {
  40. //可以从这里设置加载模板的路径
  41. $this->view->setTemplateDir(__DIR__ . "/view/");
  42. echo $this->view->fetch('index.tpl');
  43. }
  44. }