add.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 add 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. $database = $this->request->get('database');
  24. $tableName = $this->request->get('tableName');
  25. if (!$database) throw new \Exception('数据库名不能为空', __LINE__);
  26. if (!$tableName) throw new \Exception('数据表名不能为空', __LINE__);
  27. $this->controller->view->assign('database', $database);
  28. $this->controller->view->assign('tableName', $tableName);
  29. $rules = $this->controller->load->model('table')->getRules($database, $tableName);
  30. $fields = array_flip($rules['rules']['fields']);
  31. $this->controller->view->assign('rules', $rules);
  32. $this->controller->view->assign('fields', $fields);
  33. $this->controller->view->display('manage/data/add.html');
  34. }
  35. }