index.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. public function dispatchAction()
  28. {
  29. echo "<p>Dispatch start ". __CLASS__ ."</p>";
  30. $this->dispatch('test', 'index');
  31. echo "<p>Dispatch end ". __CLASS__ ."</p>";
  32. }
  33. public function forwardAction()
  34. {
  35. echo "<p>This is start section " . __CLASS__ . " Forward</p>";
  36. $this->setForward('test', 'index');
  37. echo "<p>This is end section " . __CLASS__ . " Forward</p>";
  38. }
  39. public function displayAction()
  40. {
  41. //可以从这里设置加载模板的路径
  42. $this->view->setTemplateDir(__DIR__ . "/view/");
  43. echo $this->view->fetch('index.tpl');
  44. }
  45. }