Пример #1
0
 /**
  * WebAdAct::actIndex()
  * 列出符合条件的数据并分页显示
  * @param string $condition 查询条件
  * @param integer $curpage 页码
  * @param integer $pagenum 每页个数
  * @return array 
  */
 public function actIndex()
 {
     $data = array();
     $condition = '';
     //接收参数生成条件
     $curpage = isset($_GET['page']) ? abs(intval($_GET['page'])) : 1;
     $type = isset($_GET['type']) ? trim($_GET['type']) : '';
     $key = isset($_GET['key']) ? post_check(trim($_GET['key'])) : '';
     $typeId = isset($_GET['typeId']) ? abs(intval($_GET['typeId'])) : 0;
     $condition .= "1";
     if ($type && $key) {
         if (!in_array($type, array('topic'))) {
             redirect_to("index.php?mod=webAd&act=index");
         }
         $condition .= ' AND ' . $type . " LIKE '%" . $key . "%'";
     }
     if (!empty($typeId)) {
         $condition .= " AND typeId = '{$typeId}'";
     }
     //获取符合条件的数据并分页
     $pagenum = 20;
     $total = WebAdModel::modListCount($condition);
     $res = WebAdModel::modList($condition, $curpage, $pagenum);
     $page = new Page($total, $pagenum, '', 'CN');
     $pageStr = "";
     if ($res) {
         if ($total > $pagenum) {
             $pageStr = $page->fpage(array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9));
         } else {
             $pageStr = $page->fpage(array(0, 1, 2, 3));
         }
     } else {
         $pageStr = '暂无数据';
     }
     //封装数据返回
     $data['key'] = $key;
     $data['type'] = $type;
     $data['typeId'] = $typeId;
     $data['lists'] = $res;
     $data['pages'] = $pageStr;
     self::$errCode = WebAdModel::$errCode;
     self::$errMsg = WebAdModel::$errMsg;
     if (self::$errCode != 0) {
         show_message($this->smarty, self::$errMsg, "");
         exit;
     }
     return $data;
 }