12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php namespace App\Http\Controllers\Admin;
- /**
- * 帖子类型管理
- *
- * @author 刘相欣
- *
- */
- class TopicRule extends Auth{
-
- protected function _initialize(){
- parent::_initialize();
- $this->assign('breadcrumb1','社区管理');
- $this->assign('breadcrumb2','帖子类型');
- }
- /**
- * 规则文件
- *
- */
- private function updateDesc($id,$content)
- {
- // 路径
- $path = public_path('uploads/topic/rule/detail/');
- // 如果路径不存在
- if( !is_dir($path) ) mkdir($path,0755,true);
- // 写入文件
- $result = file_put_contents($path.$id.'.html',$content);
- // 返回结果
- return $result;
- }
- /**
- * 获取规则文件内容
- *
- */
- private function getDesc($id)
- {
- // 路径
- $path = public_path('uploads/topic/rule/detail/');
- // 如果路径不存在
- if( !is_dir($path) ) mkdir($path,0755,true);
- // 不存在文件
- if( !file_exists($path.$id.'.html') ) file_put_contents($path.$id.'.html','');
- // 写入文件
- $result = (string) file_get_contents($path.$id.'.html');
- // 返回结果
- return $result;
- }
- /**
- * 列表页
- *
- * */
- public function index( ) {
- // 固定ID
- $id = 1;
- // 修改
- if( request()->isMethod('post') ) {
- // 接收数据
- $content = request('content','');
- // 写入数据表
- $id = $this->updateDesc($id,$content);
- // 如果操作失败
- if( !$id ) return json_send(['code'=>'error','msg'=>'更新失败']);
- // 告知结果
- return json_send(['code'=>'success','msg'=>'更新失败','action'=>'add']);
- }
- // 查询数据
- $oldData['id'] = $id;
- // 查询数据
- $oldData['content'] = $this->getDesc($id);
- // 分配数据
- $this->assign('oldData',$oldData);
- // 加载模板
- return $this->fetch();
- }
- }
|