TopicRule.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php namespace App\Http\Controllers\Admin;
  2. /**
  3. * 帖子类型管理
  4. *
  5. * @author 刘相欣
  6. *
  7. */
  8. class TopicRule extends Auth{
  9. protected function _initialize(){
  10. parent::_initialize();
  11. $this->assign('breadcrumb1','社区管理');
  12. $this->assign('breadcrumb2','帖子类型');
  13. }
  14. /**
  15. * 规则文件
  16. *
  17. */
  18. private function updateDesc($id,$content)
  19. {
  20. // 路径
  21. $path = public_path('uploads/topic/rule/detail/');
  22. // 如果路径不存在
  23. if( !is_dir($path) ) mkdir($path,0755,true);
  24. // 写入文件
  25. $result = file_put_contents($path.$id.'.html',$content);
  26. // 返回结果
  27. return $result;
  28. }
  29. /**
  30. * 获取规则文件内容
  31. *
  32. */
  33. private function getDesc($id)
  34. {
  35. // 路径
  36. $path = public_path('uploads/topic/rule/detail/');
  37. // 如果路径不存在
  38. if( !is_dir($path) ) mkdir($path,0755,true);
  39. // 不存在文件
  40. if( !file_exists($path.$id.'.html') ) file_put_contents($path.$id.'.html','');
  41. // 写入文件
  42. $result = (string) file_get_contents($path.$id.'.html');
  43. // 返回结果
  44. return $result;
  45. }
  46. /**
  47. * 列表页
  48. *
  49. * */
  50. public function index( ) {
  51. // 固定ID
  52. $id = 1;
  53. // 修改
  54. if( request()->isMethod('post') ) {
  55. // 接收数据
  56. $content = request('content','');
  57. // 写入数据表
  58. $id = $this->updateDesc($id,$content);
  59. // 如果操作失败
  60. if( !$id ) return json_send(['code'=>'error','msg'=>'更新失败']);
  61. // 告知结果
  62. return json_send(['code'=>'success','msg'=>'更新失败','action'=>'add']);
  63. }
  64. // 查询数据
  65. $oldData['id'] = $id;
  66. // 查询数据
  67. $oldData['content'] = $this->getDesc($id);
  68. // 分配数据
  69. $this->assign('oldData',$oldData);
  70. // 加载模板
  71. return $this->fetch();
  72. }
  73. }