index.php 2.4 KB

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