本文整理匯總了PHP中Paginate::createNavigationToObject方法的典型用法代碼示例。如果您正苦於以下問題:PHP Paginate::createNavigationToObject方法的具體用法?PHP Paginate::createNavigationToObject怎麽用?PHP Paginate::createNavigationToObject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Paginate
的用法示例。
在下文中一共展示了Paginate::createNavigationToObject方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: index
/**
* Index
*
* @param array $options : {
*
* }
* @return array
*/
public function index($options)
{
$result = ['nest' => null, 'category' => null, 'articles' => null, 'pageNavigation' => null, 'nextpage' => null];
$print = explode(',', $options['print_data']);
// get nests
if ($options['nest_id']) {
$result['nest'] = Spawn::item(['table' => Spawn::getTableName('nest'), 'where' => 'id=\'' . $options['nest_id'] . '\'', 'debug' => false]);
$result['nest'] = $result['nest'] ? $result['nest'] : null;
if (isset($result['nest']['srl'])) {
$result['nest']['json'] = Util::jsonToArray($result['nest']['json'], false, true);
} else {
return ['state' => 'error', 'message' => 'not found nest data'];
}
// get categories list
if ($result['nest']['json']['useCategory'] && $this->searchKeyInArray($print, 'category')) {
$result['category'] = Spawn::items(['table' => Spawn::getTableName('category'), 'where' => 'nest_srl=' . (int) $result['nest']['srl'], 'field' => 'srl,name', 'order' => 'turn', 'sort' => 'asc']);
$cnt_all = Spawn::count(['table' => Spawn::getTableName('article'), 'where' => 'app_srl=' . $options['app_srl'] . ' and nest_srl=' . (int) $result['nest']['srl']]);
if (count($result['category'])) {
$check_active = false;
$index = [['srl' => 0, 'name' => 'All', 'count' => $cnt_all, 'active' => false]];
foreach ($result['category'] as $k => $v) {
$cnt = $cnt_all > 0 ? Spawn::count(['table' => Spawn::getTableName('article'), 'where' => 'category_srl=' . (int) $v['srl']]) : 0;
if ($options['category_srl'] == (int) $v['srl']) {
$check_active = true;
}
$index[] = ['srl' => (int) $v['srl'], 'name' => $v['name'], 'count' => $cnt, 'active' => $options['category_srl'] == (int) $v['srl']];
}
if (!$check_active) {
$index[0]['active'] = true;
}
$result['category'] = $index;
}
}
}
// get articles
// init paginate
require_once __GOOSE_PWD__ . 'core/classes/Paginate.class.php';
$options['page'] = $options['page'] > 1 ? $options['page'] : 1;
$count = $options['count'];
$scale = $options['pageScale'];
$params = ['keyword' => $_GET['keyword'] ? $_GET['keyword'] : ''];
$nest_srl = $options['nest_id'] ? isset($result['nest']['srl']) ? $result['nest']['srl'] : -1 : null;
$where = 'app_srl=' . $options['app_srl'];
$where .= $nest_srl ? ' and nest_srl=' . $nest_srl : '';
$where .= $options['category_srl'] ? ' and category_srl=' . (int) $options['category_srl'] : '';
$where .= $_GET['keyword'] ? ' and (title LIKE "%' . $_GET['keyword'] . '%" or content LIKE "%' . $_GET['keyword'] . '%")' : '';
// get total article
$total = Spawn::count(['table' => Spawn::getTableName('article'), 'where' => $where]);
// set paginate instance
$paginate = new Paginate($total, $_GET['page'], $params, $count, $scale);
// set limit
$limit = $paginate->offset . ',' . $paginate->size;
// get articles
$result['articles'] = Spawn::items(['table' => Spawn::getTableName('article'), 'field' => 'srl,nest_srl,category_srl,hit,json,regdate,title', 'where' => $where, 'limit' => $limit, 'sort' => 'desc', 'order' => 'srl']);
// adjustment articles
if ($this->searchKeyInArray($print, 'article')) {
foreach ($result['articles'] as $k => $v) {
if (isset($v['regdate'])) {
$result['articles'][$k]['regdate'] = Util::convertDate($v['regdate']);
}
if (isset($v['modate'])) {
$result['articles'][$k]['modate'] = Util::convertDate($v['modate']);
}
if (isset($v['category_srl'])) {
$category = Spawn::item(['table' => Spawn::getTableName('category'), 'where' => 'srl=' . (int) $v['category_srl']]);
$result['articles'][$k]['category_name'] = isset($category['name']) ? $category['name'] : '';
}
$result['articles'][$k]['json'] = Util::jsonToArray($v['json'], false, true);
}
}
// set paginate
if ($this->searchKeyInArray($print, 'nav_paginate')) {
$result['pageNavigation'] = $paginate->createNavigationToObject();
}
// set nextpage
if ($this->searchKeyInArray($print, 'nav_more')) {
$nextPaginate = new Paginate($total, $options['page'] + 1, $params, $count, $scale);
$limit = $nextPaginate->offset . ',' . $nextPaginate->size;
$nextArticles = Spawn::items(['table' => Spawn::getTableName('article'), 'field' => 'srl', 'where' => $where, 'limit' => $limit, 'sort' => 'desc', 'order' => 'srl']);
$result['nextpage'] = count($nextArticles) ? $options['page'] + 1 : null;
}
$result['nest'] = $this->searchKeyInArray($print, 'nest') ? $result['nest'] : null;
$result['articles'] = $this->searchKeyInArray($print, 'article') ? $result['articles'] : null;
$result['state'] = 'success';
return $result;
}