ArticleClassModel.class.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace Admin\Model;
  3. use Think\Model;
  4. /**
  5. * 文章分类模型
  6. * @author Devil
  7. * @blog http://gong.gg/
  8. * @version 0.0.1
  9. * @datetime 2016-12-01T21:51:08+0800
  10. */
  11. class ArticleClassModel extends CommonModel
  12. {
  13. // 数据自动校验
  14. protected $_validate = array(
  15. // 添加,编辑
  16. array('name', 'CheckName', '{%common_name_format}', 1, 'callback', 3),
  17. array('is_enable', array(0,1), '{%common_enable_tips}', 1, 'in', 3),
  18. array('sort', 'CheckSort', '{%common_sort_error}', 1, 'function', 3),
  19. // 删除校验是否存在子级
  20. array('id', 'IsExistSon', '{%common_is_exist_son_error}', 1, 'callback', 5),
  21. );
  22. /**
  23. * [CheckName 文章分类名称校验]
  24. * @author Devil
  25. * @blog http://gong.gg/
  26. * @version 0.0.1
  27. * @datetime 2016-12-13T19:29:30+0800
  28. */
  29. public function CheckName()
  30. {
  31. $len = Utf8Strlen(I('name'));
  32. return ($len >= 2 && $len <= 16);
  33. }
  34. /**
  35. * [IsExistSon 校验节点下是否存在子级数据]
  36. * @author Devil
  37. * @blog http://gong.gg/
  38. * @version 0.0.1
  39. * @datetime 2016-12-10T14:09:40+0800
  40. */
  41. public function IsExistSon()
  42. {
  43. return ($this->db(0)->where(array('pid'=>I('id')))->count() == 0);
  44. }
  45. }
  46. ?>