public function defaultAction() { $pageSize = 50; $page = Pager::get(); $category = (int) Request::getGET('category', -1); $title = trim(Request::getGET('title', '')); $username = trim(Request::getGET('username', '')); $where = array(); if ($category != -1) { $where[] = array('category', '=', $category); } if (!empty($username)) { $userInfo = UserCommonInterface::getByLoginName(array('login_name' => $username)); $where[] = array('user_id', '=', Arr::get('id', $userInfo, 0)); } if (!empty($title)) { $where[] = array('title', 'LIKE', "%{$title}%"); } if ($category != -1) { $order = array('hidden' => 'ASC', 'title' => 'ASC', 'id' => 'DESC'); } else { $order = array('id' => 'DESC'); } $offset = ($page - 1) * $pageSize; $docList = DocInterface::getList(array('where' => $where, 'order' => $order, 'limit' => $pageSize, 'offset' => $offset)); $allCount = empty($docList) ? 0 : DocInterface::getCount($where); $userIds = array_unique(array_column($docList, 'user_id')); $userHash = UserCommonInterface::getById(array('id' => $userIds)); // 缓存部分的html $html = array(); $html['pager'] = $this->view->fetch(array('renderAllCount' => $allCount, 'renderPageSize' => $pageSize, 'renderRadius' => 7), 'widget/pager.php'); $this->renderFramework(array('html' => $html, 'docList' => $docList, 'userHash' => $userHash), 'doc/list.php'); }
public function defaultAction() { $docId = (int) Request::getGET('doc-id', 0); $docInfo = array(); if (!empty($docId)) { $docInfo = DocInterface::getById(array('id' => $docId)); if (empty($docInfo) || $docInfo['hidden'] || $docInfo['category'] != 1) { $this->renderError('文章不存在!'); } } $where = array(); $where[] = array('category', '=', 1); $where[] = array('hidden', '=', 0); $where[] = array('title', '!=', ''); $order = array('title' => 'ASC'); $docList = DocInterface::getList(array('where' => $where, 'order' => $order)); $this->renderFramework(array('docList' => $docList, 'docInfo' => $docInfo), 'doc/list.php'); }