PersonalController.class.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace Home\Controller;
  3. /**
  4. * 个人资料
  5. * @author Devil
  6. * @blog http://gong.gg/
  7. * @version 0.0.1
  8. * @datetime 2017-03-02T22:48:35+0800
  9. */
  10. class PersonalController extends CommonController
  11. {
  12. /**
  13. * [_initialize 前置操作-继承公共前置方法]
  14. * @author Devil
  15. * @blog http://gong.gg/
  16. * @version 0.0.1
  17. * @datetime 2017-03-02T22:48:35+0800
  18. */
  19. public function _initialize()
  20. {
  21. // 调用父类前置方法
  22. parent::_initialize();
  23. // 登录校验
  24. $this->Is_Login();
  25. }
  26. /**
  27. * [Index 首页]
  28. * @author Devil
  29. * @blog http://gong.gg/
  30. * @version 0.0.1
  31. * @datetime 2017-02-22T16:50:32+0800
  32. */
  33. public function Index()
  34. {
  35. $this->assign('personal_show_list', L('personal_show_list'));
  36. $this->display('Index');
  37. }
  38. /**
  39. * [SaveInfo 编辑页面]
  40. * @author Devil
  41. * @blog http://gong.gg/
  42. * @version 0.0.1
  43. * @datetime 2017-03-26T14:26:01+0800
  44. */
  45. public function SaveInfo()
  46. {
  47. // 性别
  48. $this->assign('common_gender_list', L('common_gender_list'));
  49. // 数据
  50. $this->assign('data', $this->user);
  51. $this->display('SaveInfo');
  52. }
  53. /**
  54. * [Save 数据保存]
  55. * @author Devil
  56. * @blog http://gong.gg/
  57. * @version 0.0.1
  58. * @datetime 2017-03-26T14:26:34+0800
  59. */
  60. public function Save()
  61. {
  62. // 是否ajax请求
  63. if(!IS_AJAX)
  64. {
  65. $this->error(L('common_unauthorized_access'));
  66. }
  67. // 个人资料模型
  68. $m = D('Personal');
  69. // 编辑
  70. if($m->create($_POST, 2))
  71. {
  72. // 额外数据处理
  73. $m->birthday = strtotime(I('birthday'));
  74. $m->nickname = I('nickname');
  75. $m->signature = I('signature');
  76. $m->describe = I('describe');
  77. $m->upd_time = time();
  78. // 更新数据库
  79. if($m->where(array('id'=>$this->user['id']))->save())
  80. {
  81. // 更新用户session数据
  82. $this->UserLoginRecord($this->user['id']);
  83. $this->ajaxReturn(L('common_operation_edit_success'));
  84. } else {
  85. $this->ajaxReturn(L('common_operation_edit_error'), -100);
  86. }
  87. } else {
  88. $this->ajaxReturn($m->getError(), -1);
  89. }
  90. }
  91. }
  92. ?>