ThinkSSL🔒 一键申购 5分钟快速签发 30天无理由退款 购买更放心 广告
## 2020年08月20日 ## 修复存储数据单引号`'`问题 1、打开文件: ``` \Chuanhai\Class\Db.class.php ``` 2、大约在292行:找到`foreach($data as $key=>$v){`在后面新起一行,加入以下代码: ``` $v = str_replace("'",'"',$v); ``` ## 修改后台信息列表分页数字过长问题: ![](https://img.kancloud.cn/e2/c7/e2c78872e5b887520e45cb4d91ced4e6_1257x96.png) 由于分页调用了构造函数:quickPage(),而它又调用了getPageHtml(),所以修改为: 1.在 Chuanhai/Class/Page.class.php下找到“setPageHtml”方法,改为以下代码: ``` /* * 设置分页html */ private function setPageHtml(){ //总页码 $this->countPage; //当前页码 $this->page; //生成页码url $this->getPageUrl(1); //设置模板渲染的分页Html $this->pageHtml; //一行显示多少个页码 $line\_num = 10; $i\_start = 1; $i\_end = $this->countPage; //组建分页html $this->pageHtml = ''; if($this->page > $line\_num/2 && $this->countPage>$line\_num){ $this->pageHtml .= 'getPageUrl(1).'">1...'; $i\_start = $this->page - floor($line\_num/2); if($this->page countPage - floor($line\_num/2)){ $i\_end = $this->page + floor($line\_num/2) -1; } if($i\_end - $i\_start +1 != $line\_num){ $cNumber = floor($line\_num/2) - ($this->countPage - $this->page +1); $i\_start = $i\_start - $cNumber; } }else if($this->countPage > $line\_num){ $i\_end = $line\_num; } //上一页 $this->pageHtml .= ($this->page>1)?'getPageUrl($this->page-1).'">':''; //$i\_end = ($this->pagecountPage-$line\_num))?$this->page+($line\_num/2):$this->page; //$i\_start = ($this->page>$line\_num)?$this->page-($line\_num/2):$this->page; //循环页码 for($i=$i\_start;$i<=$i\_end;$i++){ $this->pageHtml .= ($i!=$this->page)?'getPageUrl($i).'">'.$i.'':''.$i.''; } //下一页 $this->pageHtml .= ($this->pagecountPage)?'getPageUrl($this->page+1).'">>>':''; //尾页 if($this->page!=$this->countPage && $i\_end countPage){ $this->pageHtml .= 'getPageUrl($this->countPage).'">...'.$this->countPage.''; } $this->pageHtml .= ''; } ``` 2.app/index/webpage/index/controller/Info Controller.class.php 替换栏目页方法: ``` //栏目页 public function column(){ //初始化data $this->data = array( 'id' => I('id',0,'intval'), ); //验证 if(!$this->data['id']) $this->ajaxReturn(array('status'=>1,'message'=>'id error')); //查询栏目 $columnResult = M('info_column') ->alias('a') ->field('*') ->where('a.id='.$this->data['id']) ->join('__INFO_COLUMN_A__ as b on b.mainId=a.id') ->find(); //没有数据 if(!$columnResult) $this->ajaxReturn(array('status'=>1,'message'=>'id error')); //合并数据 $this->data = array_merge($this->data,$columnResult); //栏目url $this->data['url'] = staticUrl('info','column',array('id'=>$this->data['id'])); //栏目位置 $columnPosition = recursionGetColumnPosition($this->allColumn,$this->data['id']); //顶级栏目id $this->data['topId'] = (isset($columnPosition[0]['id']))?$columnPosition[0]['id']:0; //循环处理 foreach($columnPosition as $key=>$v){ //添加到位置 $this->position[] = array( 'id' => $v['id'], 'name' => $v['name'], 'url' => staticUrl('info','column',array('id'=>$v['id'])), ); } //如果栏目类型是单篇 $this->data['info'] = array(); if($this->data['type']==1){ //查询信息 $infoResult = M('info_info') ->alias('a') ->where('a.columnId='.$this->data['id']) ->join('__INFO_INFO_A__ as b on b.mainId=a.id') ->join('__INFO_INFO_B__ as c on c.mainId=a.id') ->order('a.sort asc,a.addTime desc,a.id desc') ->find(); $this->data['info'] = $infoResult; //信息url $this->data['info']['url'] = staticUrl('info','content',array('id'=>$this->data['info']['id'])); //栏目jumpUrl if($this->data['info']['jumpUrl']){ $this->data['jumpUrl'] = $this->data['info']['jumpUrl']; } } //所有下级栏目 $allChildrenColumnResult = levelRecursion($this->allColumn,'',$this->data['id']); //统计下级栏目数量 $childrenColumnCount = M('info_column') ->alias('a') ->where('parentId='.$this->data['id']) ->join('__INFO_COLUMN_A__ as b on b.mainId=a.id') ->count(); //获取下级栏目的上级id $getParentId = ($childrenColumnCount)?$this->data['id']:$this->data['parentId']; //下级栏目 $childrenColumnResult = M('info_column') ->alias('a') ->field('*') ->where('a.parentId='.$getParentId) ->join('__INFO_COLUMN_A__ as b on b.mainId=a.id') ->order('sort asc,id asc') ->select(); $this->data['childrenColumn'] = $childrenColumnResult; //循环处理 foreach($this->data['childrenColumn'] as $key=>$v){ //生成url $v['url'] = staticUrl('info','column',array('id'=>$v['id'])); //更新数据 $this->data['childrenColumn'][$key] = $v; } //快捷分页数据 $quickPageArr = array( 'table' => 'info_info', 'alias' => 'a', 'field' => 'a.*,b.*,c.*', 'where' => 'a.toStatus=1 && e.type=0', 'join' => array( '__INFO_INFO_A__ as b on b.mainId=a.id', '__INFO_INFO_B__ as c on c.mainId=a.id', '__INFO_COLUMN__ as d on d.id=a.columnId', '__INFO_COLUMN_A__ as e on e.mainId=a.columnId', ), 'order' => 'a.sort asc,a.addTime desc,a.id desc', 'pageNum' => $this->data['pageNum'], 'setUrl' => $this->data['url'], ); //加入栏目id条件 $quickPageArr['where'] .= ' && (a.columnId='.$this->data['id']; foreach($allChildrenColumnResult as $key=>$v){ $quickPageArr['where'] .= ' || a.columnId='.$v['id']; } $quickPageArr['where'] .= ')'; //快捷分页 $this->data = array_merge($this->data,$this->quickPage($quickPageArr)); //循环处理 foreach($this->data['list'] as $key=>$v){ //生成信息url $v["url"] = staticUrl("info","content",array("id"=>$v["id"])); //更新数据 $this->data['list'][$key] = $v; } //数据分配 $this->info = $this->data['info']; $this->column = $this->data; $this->list = $this->data['list']; $this->page = $this->data['page']; $this->childrenColumn = $this->data['childrenColumn']; //注销数据 unset($this->column['info']); unset($this->column['list']); unset($this->column['page']); unset($this->column['childrenColumn']); //设置seo数据 $this->set['pageTitle'] = ($this->column['pageTitle'])?$this->column['pageTitle']:$this->column['name'].' - '.$this->set['name']; $this->set['pageKeyword'] = ($this->column['pageKeyword'])?$this->column['pageKeyword']:$this->set['name']; $this->set['pageDescription'] = $this->column['pageDescription']; /* dump($this->info); dump($this->column); dump($this->list); dump($this->position); dump($this->childrenColumn); exit();*/ //跳转url处理 $this->jump($this->column['jumpUrl']); $this->display($this->data['listTemplate']); } ```