creator.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 creator 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. $args = func_get_args();
  24. list($database, $tableName) = array_pad($args, 2, '');
  25. $loadDatabase = $database ? false : true;
  26. $this->controller->view->assign('loadDatabase', $loadDatabase);
  27. $tableName = $this->request->get('tableName', $tableName);
  28. $database = $this->request->get('database', $database);
  29. try {
  30. $databases = $this->controller->load->model('table')->getDatabases();
  31. if (!$database && count($database) > 0) $database = $databases[0];
  32. $this->controller->view->assign('databases', $databases);
  33. $tables = $this->controller->load->model('table')->getTableLists($database);
  34. if (!$tableName && count($tables) > 0) {
  35. $tableName = $tables[0];
  36. }
  37. $this->controller->view->assign('tables', $tables);
  38. $fields = array();
  39. $rules = array();
  40. if ($tableName != '') {
  41. $fields = $this->controller->load->model('table')->getFieldsLists($database, $tableName);
  42. $rules = $this->controller->load->model('table')->getRules($database, $tableName);
  43. if (!isset($rules['rules'])) $rules['rules'] = array();
  44. }
  45. $validateRules = isset($rules['rules']['validate']) ? $rules['rules']['validate'] : array();
  46. $this->controller->view->assign('validateRules', $validateRules);
  47. $validate = new \Qii\Library\Validate();
  48. $this->controller->view->assign('validate', $validate->getRuleNames());
  49. $this->controller->view->assign('fields', $fields);
  50. $this->controller->view->assign('rules', isset($rules['rules']) ? $rules['rules'] : array());
  51. $this->controller->view->assign('database', $database);
  52. $this->controller->view->assign('tableName', $tableName);
  53. $this->controller->view->display('manage/data/creator.html');
  54. } catch (Exception $e) {
  55. $this->showErrorPage($e->getMessage());
  56. }
  57. }
  58. }