table.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * 数据管理
  4. * @author Jinhui Zhu <jinhui.zhu@live.cn>2015-09-21
  5. *
  6. */
  7. namespace actions\database;
  8. use Qii\Base\Action;
  9. class table extends Action
  10. {
  11. public $enableView = true;
  12. public $enableDB = true;
  13. public function __construct()
  14. {
  15. parent::__construct();
  16. }
  17. /**
  18. * 创建规则
  19. * @author Jinhui Zhu 2015-08-23
  20. */
  21. public function run()
  22. {
  23. list($database, $tableName) = array_pad(func_get_args(), 2, '');
  24. $loadDatabase = true;
  25. $this->controller->view->assign('controller', $this->_controller);
  26. $this->controller->view->assign('action', $this->_action);
  27. try {
  28. $this->controller->view->assign('loadDatabase', $loadDatabase);
  29. $database = $this->request->get('database', $database);
  30. $tableName = $this->request->get('tableName', $tableName);
  31. $currentPage = $this->request->get('currentPage', 1);
  32. $databases = array();
  33. $tables = array();
  34. if ($loadDatabase) {
  35. $databases = $this->controller->load->model('table')->getDatabases();
  36. if (!$database && count($database) > 0) $database = $databases[0];
  37. if (!$database) throw new \Exception('数据库名不能为空', __LINE__);
  38. $tables = $this->controller->load->model('table')->getTableLists($database);
  39. if (!$tableName && count($tables) > 0) {
  40. $tableName = $tables[0];
  41. }
  42. }
  43. $this->controller->view->assign('databases', $databases);
  44. $this->controller->view->assign('tables', $tables);
  45. $this->controller->view->assign('database', $database);
  46. $this->controller->view->assign('tableName', $tableName);
  47. $data = array();
  48. $data['page'] = array();
  49. $data['page']['currentPage'] = 1;
  50. $data['page']['totalPage'] = 0;
  51. $data['page']['total'] = 0;
  52. $data['rules'] = array();
  53. $data['rules']['end'] = array();
  54. $data['rows'] = array();
  55. if ($tableName) {
  56. $data = $this->controller->load->model('table')->loadTableData($database, $tableName, $currentPage);
  57. }
  58. $start = 0;
  59. if ($data['page']['currentPage'] >= 6) {
  60. $start = $data['page']['currentPage'] - 6;
  61. }
  62. $this->controller->view->assign('start', $start);
  63. $this->controller->view->assign('data', $data);
  64. $this->controller->view->assign('pages', $data['page']);
  65. $this->controller->view->display('manage/data/table.html');
  66. } catch (Exception $e) {
  67. $this->showErrorPage($e->getMessage());
  68. }
  69. }
  70. }