rules.php 2.5 KB

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