12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- namespace controller;
- class index extends \Qii\Base\Controller
- {
- public $enableDB = true;
- public $enableView = true;
- public function indexAction()
- {
- $html = [];
- $html[] = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>示例程序</title>';
- $html[] = '<style>ul{list-style:none;font-size:16px;}a{text-decoration: none;color: #1F3D74}</style>';
- $html[] = '</head><body>';
- $html[] = '<ul>示例程序';
- $html[] = '<li>1. <a href="'. _link('dirs.html') .'">文件管理</a></li>';
- $html[] = '<li>2. <a href="'. _link('database/creator.html') .'">数据表管理</a></li>';
- $html[] = '<li>3. <a href="'. _link('index/dispatch.html') .'">Dispatch</a></li>';
- $html[] = '<li>4. <a href="'. _link('index/forward.html') .'">Forward</a></li>';
- $html[] = '<li>5. <a href="'. _link('index/display.html') .'">使用指定目录中的模板</a></li>';
- $html[] = '</ul>';
- $html[] = '</body></html>';
- return $this->setResponse(new \Qii\Base\Response(array('format' => 'html', 'body' => join("\n", $html))));
- return;
- $data = array();
- $data['lists'][] = $this->db->getRow('SELECT * FROM ipAddress ORDER BY id DESC LIMIT 1');
- $data['lists'][] = $this->db->getRow('SELECT * FROM ipAddress ORDER BY id ASC LIMIT 1');
- $data['querySeconds'] = $this->db->querySeconds;
-
- return new \Qii\Base\Response(array('format' => 'json', 'body' => $data));
- }
- /**
- * 设置controller中间件,此中间件将会在controller初始化之前使用
- * @return array
- */
- public function getMiddleware()
- {
- return parent::getMiddleware(); // TODO: Change the autogenerated stub
- }
- public function dispatchAction()
- {
- echo "<p>Dispatch start ". __CLASS__ ."</p>";
- $this->dispatch('test', 'index');
- echo "<p>Dispatch end ". __CLASS__ ."</p>";
- }
-
- public function forwardAction()
- {
- echo "<p>This is start section " . __CLASS__ . " Forward</p>";
- $this->setForward('test', 'index');
- echo "<p>This is end section " . __CLASS__ . " Forward</p>";
- }
- public function displayAction()
- {
- //可以从这里设置加载模板的路径
- $this->view->setTemplateDir(__DIR__ . "/view/");
- echo $this->view->fetch('index.tpl');
- }
- }
|