/** * 文章详情前置方法 */ public function _before_detail() { /** 判断是否禁止访问 **/ if (!checkStaus('Document', I('id'))) { $this->error('禁止访问'); } /** 增加点击量 **/ addHits('Document', I('id')); }
public function show() { //根据ID获取记录并循环非配 $id = empty($_REQUEST['id']) ? '0' : $_REQUEST['id']; $cat_id = empty($_REQUEST['cat_id']) ? '0' : $_REQUEST['cat_id']; if ($id == 0) { throw new Exception('AtricleId Error!!'); } $top_parent_id = top_parent($cat_id); $origin_cat = CMS_M('category')->where('category_id=' . $cat_id)->find(); $this->assign('origin_cat', $origin_cat); $top_parent_cat = CMS_M('category')->where('category_id=' . $top_parent_id)->find(); $module_id = $top_parent_cat['module_id']; $table = CMS_M('cm_table')->where('table_id=' . $module_id)->find(); $m = CMS_M($table['table_name']); $pk = $m->getPk(); $res = $m->where($pk . '=' . $id)->find(); foreach ($res as $key => $val) { $this->assign('show_' . $key, $val); } //获取上一条与下一条记录 $cat_id = $res['cat_id']; $preNextInfo = $m->where('cat_id=' . $cat_id)->select(); $pre = ''; $next = ''; foreach ($preNextInfo as $key => $val2) { $positionNow = -1; foreach ($preNextInfo as $keyPos => $rowPos) { if ($rowPos[$pk] == $res[$pk]) { $positionNow = $keyPos; } } if ($val2[$pk] == $res[$pk] && $positionNow > 0) { $pre = '<a href="' . CON_PATH . '/' . $preNextInfo[$key - 1][$pk] . '/cat_id/' . $cat_id . '">' . $preNextInfo[$key - 1]['title'] . '</a>'; } if ($val2[$pk] == $res[$pk] && $positionNow < count($preNextInfo) - 1) { $next = '<a href="' . CON_PATH . '/' . $preNextInfo[$key + 1][$pk] . '/cat_id/' . $cat_id . '">' . $preNextInfo[$key + 1]['title'] . '</a>'; } } $pre = $pre == '' ? '<a href="#">第一条</a>' : $pre; $next = $next == '' ? '<a href="#">最后一条</a>' : $next; $this->assign('pre', $pre); $this->assign('next', $next); addHits($id, $cat_id); //addFavor($id,$cat_id); //echo getCurrentTpl();echo '---';exit; $this->showTpl(getCurrentTpl()); }