当前位置: 首页>>代码示例>>PHP>>正文


PHP Paginator::factory方法代码示例

本文整理汇总了PHP中Paginator::factory方法的典型用法代码示例。如果您正苦于以下问题:PHP Paginator::factory方法的具体用法?PHP Paginator::factory怎么用?PHP Paginator::factory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Paginator的用法示例。


在下文中一共展示了Paginator::factory方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: index

 public function index()
 {
     $paginator = Paginator::factory(1024);
     $pages = $paginator->setItemCountPerPage(30)->setCurrentPageNumber($this->getRequest()->getParam('page', 1))->setPageRange(10)->getPages();
     $this->view = View::factory('pagination');
     $this->view->assign('url', $this->getBaseUrl() . $this->getRequest()->uri() . '/page/');
     $this->view->assign('pages', $pages);
     $this->view->render();
 }
开发者ID:atlas1308,项目名称:testtesttestfarm,代码行数:9,代码来源:pagination.php

示例2: action_index

 public function action_index()
 {
     $posts = ORM::factory('Post')->order_by('post.created', 'DESC')->find_all();
     $paginator = Paginator::factory($posts);
     $paginator->set_item_count_per_page(5);
     $paginator->set_current_page_number(Arr::get($_GET, 'page', 1));
     $this->template->title = 'Admin';
     $this->template->content = View::factory('admin/index')->set('posts', $paginator);
 }
开发者ID:DavBfr,项目名称:BlogMVC,代码行数:9,代码来源:Admin.php

示例3: action_author

 public function action_author()
 {
     $slug = $this->request->param('user');
     $user = ORM::factory('User')->where('user.id', '=', $slug)->find();
     if (!$user->loaded()) {
         throw HTTP_Exception::factory(404);
     }
     $paginator = Paginator::factory($user->posts->order_by('created', 'DESC')->find_all());
     $paginator->set_item_count_per_page(5);
     $paginator->set_current_page_number(Arr::get($_GET, 'page', 1));
     $data = array('user' => $user, 'posts' => $paginator);
     $this->template->title = $user->username;
     $this->template->content = View::factory('blog/author', $data);
 }
开发者ID:DavBfr,项目名称:BlogMVC,代码行数:14,代码来源:Posts.php

示例4: get

 /**
  *
  * Get parsed html of user questions div,
  * complete with pagination
  *
  * @todo there has to be an extra request param "tab" and ONLY if
  * it equals to 'questions' then it would mean
  * that sort and pagination is for this block because it could
  * be for 'answer' block since they both come to the same controller
  * OR just make separate controllers and then pagination and sorting
  * will work ONLY with AJAX  and then just hide pagination from
  * non-js browsers!
  *
  * @param Registry $Registry
  * @param User $User
  *
  * @return string html of user questions
  */
 public static function get(Registry $Registry, User $User)
 {
     $uid = $User->getUid();
     if (0 === $uid) {
         d('not registered user');
         return '';
     }
     $pagerLinks = '';
     $pageID = $Registry->Request->get('pageID', 'i', 1);
     /**
      * Default pager path
      */
     $pagerPath = '/tab/q/' . $uid . '/recent';
     /**
      * Default sort condition
      *
      * @var array
      */
     $sort = array('i_ts' => 1);
     //$mode = $Registry->Request->get('tab', 's', '');
     /**
      * sort order possible values:
      * recent, oldest, voted, updated, views
      *
      * default is oldest first
      *
      * $mode 'questions' means that user requested
      * either pagination or sorting specifically
      * for the User Questions
      * This is not necessaraly an ajax request as pagination
      * will work without Ajax too.
      *
      * When there is no explicit 'questions' $mode
      * then we need to just get the cursor
      * with default sort and pageID, treating this
      * request as if it was for pageID 1 and sort=oldest
      */
     //if('q' === $mode){
     $cond = $Registry->Request->get('sort', 's', 'recent');
     switch ($cond) {
         case 'recent':
             $sort = array('i_ts' => -1);
             $pagerPath = '/tab/q/' . $uid . '/recent';
             break;
         case 'voted':
             $sort = array('i_votes' => -1);
             $pagerPath = '/tab/q/' . $uid . '/voted';
             break;
         case 'updated':
             $sort = array('i_etag' => -1);
             $pagerPath = '/tab/q/' . $uid . '/updated';
             break;
         case 'views':
             $sort = array('i_views' => -1);
             $pagerPath = '/tab/q/' . $uid . '/views';
             break;
         default:
             $sort = array('i_ts' => 1);
             $pagerPath = '/tab/q/' . $uid . '/oldest';
             break;
     }
     //}
     $cursor = self::getCursor($Registry, $uid, $sort);
     $count = $cursor->count(true);
     d('$count: ' . $count);
     /**
      * If this user does not have any questions then return
      * empty string
      */
     if (0 == $count) {
         d('no user questions');
         return '';
     }
     if ($count > self::PER_PAGE || $pageID > 1) {
         $oPaginator = Paginator::factory($Registry);
         $oPaginator->paginate($cursor, self::PER_PAGE, array('path' => $pagerPath));
         $pagerLinks = $oPaginator->getLinks();
         d('links: ' . $pagerLinks);
     }
     $questions = \tplUquestions::loop($cursor);
     d('questions: ' . $questions);
     $vals = array('{count}' => $count, '{questions}' => $questions, '{pagination}' => $pagerLinks);
//.........这里部分代码省略.........
开发者ID:netconstructor,项目名称:LampCMS,代码行数:101,代码来源:UserQuestions.php

示例5: get

 public static function get(Registry $Registry, User $User)
 {
     $uid = $User->getUid();
     if (0 === $uid) {
         d('not registered user');
         return '';
     }
     $pagerLinks = '';
     /**
      * Default pager path
      */
     $pagerPath = '/tab/a/' . $uid . '/oldest';
     $cond = $Registry->Request->get('sort', 's', 'recent');
     switch ($cond) {
         case 'oldest':
             $sort = array('_id' => 1);
             $pagerPath = '/tab/a/' . $uid . '/recent';
             break;
         case 'voted':
             $sort = array('i_votes' => -1);
             $pagerPath = '/tab/a/' . $uid . '/voted';
             break;
         case 'updated':
             $sort = array('i_lm_ts' => -1);
             $pagerPath = '/tab/a/' . $uid . '/updated';
             break;
         case 'best':
             $sort = array('accepted' => -1);
             $pagerPath = '/tab/a/' . $uid . '/best';
             break;
         default:
             $sort = array('_id' => -1);
             $pagerPath = '/tab/a/' . $uid . '/oldest';
             break;
     }
     $cursor = self::getCursor($Registry, $uid, $sort);
     $count = $cursor->count(true);
     d('$count: ' . $count);
     /**
      * If this user does not have any answers then return
      * empty string, skip any unnecessary template parsing
      */
     if (0 == $count) {
         d('no user answers');
         return '';
     }
     $pageID = $Registry->Request->get('pageID', 'i', 1);
     if ($count > self::PER_PAGE || $pageID > 1) {
         $oPaginator = Paginator::factory($Registry);
         $oPaginator->paginate($cursor, self::PER_PAGE, array('path' => $pagerPath));
         $pagerLinks = $oPaginator->getLinks();
         d('$pagerPath: ' . $pagerPath . ' pagerLinks: ' . $pagerLinks);
     }
     $answers = \tplUanswers::loop($cursor);
     d('$answers: ' . $answers);
     $vals = array('count' => $count, 'answers' => $answers, 'pagination' => $pagerLinks);
     return \tplUserAnswers::parse($vals);
 }
开发者ID:netconstructor,项目名称:LampCMS,代码行数:58,代码来源:UserAnswers.php

示例6: get

 /**
  *
  * Get parsed html of user questions div,
  * complete with pagination
  *
  * @todo there has to be an extra request param "tab" and ONLY if
  *       it equals to 'questions' then it would mean
  *       that sort and pagination is for this block because it could
  *       be for 'answer' block since they both come to the same controller
  *       OR just make separate controllers and then pagination and sorting
  *       will work ONLY with AJAX  and then just hide pagination from
  *       non-js browsers!
  *
  * @param Registry $Registry
  * @param User     $User
  *
  * @return string html of user questions
  */
 public static function get(Registry $Registry, User $User)
 {
     $perPage = $Registry->Ini->PROFILE_QUESTIONS_PER_PAGE;
     $uid = $User->getUid();
     if (0 === $uid) {
         d('not registered user');
         return '';
     }
     /**
      * @var string
      */
     $pagerLinks = '';
     /**
      * @var int
      */
     $pageID = $Registry->Router->getPageID();
     /**
      * @var array
      */
     $aUriMap = $Registry->Ini->getSection('URI_PARTS');
     //$mode = $Registry->Request->get('tab', 's', '');
     /**
      * sort order possible values:
      * recent, oldest, voted, updated, views
      *
      * default is oldest first
      *
      * $mode 'questions' means that user requested
      * either pagination or sorting specifically
      * for the User Questions
      * This is not necessarily an ajax request as pagination
      * will work without Ajax too.
      *
      * When there is no explicit 'questions' $mode
      * then we need to just get the cursor
      * with default sort and pageID, treating this
      * request as if it was for pageID 1 and sort=oldest
      */
     //if('q' === $mode){
     $cond = $Registry->Router->getSegment(3, 's', $aUriMap['SORT_RECENT']);
     d('$cond: ' . $cond);
     switch ($cond) {
         case $aUriMap['SORT_RECENT']:
             $sort = array('i_ts' => -1);
             $pagerPath = '{_WEB_ROOT_}/{_userinfotab_}/q/' . $uid . '/{_SORT_RECENT_}';
             break;
         case $aUriMap['SORT_VOTED']:
             $sort = array('i_votes' => -1);
             $pagerPath = '{_WEB_ROOT_}/{_userinfotab_}/q/' . $uid . '/{_SORT_VOTED_}';
             break;
         case $aUriMap['SORT_UPDATED']:
             $sort = array('i_etag' => -1);
             $pagerPath = '{_WEB_ROOT_}/{_userinfotab_}/q/' . $uid . '/{_SORT_UPDATED_}';
             break;
         case $aUriMap['SORT_VIEWS']:
             $sort = array('i_views' => -1);
             $pagerPath = '{_WEB_ROOT_}/{_userinfotab_}/q/' . $uid . '/{_SORT_VIEWS_}';
             break;
         default:
             $sort = array('i_ts' => 1);
             $pagerPath = '{_WEB_ROOT_}/{_userinfotab_}/q/' . $uid . '/{_SORT_OLDEST_}';
             break;
     }
     //}
     $cursor = self::getCursor($Registry, $uid, $sort);
     $count = $cursor->count(true);
     d('$count: ' . $count);
     /**
      * If this user does not have any questions then return
      * empty string
      */
     if (0 == $count) {
         d('no user questions');
         return '';
     }
     if ($count > $perPage || $pageID > 1) {
         $Paginator = Paginator::factory($Registry);
         $Paginator->paginate($cursor, $perPage, array('path' => $pagerPath, 'currentPage' => $pageID));
         $pagerLinks = $Paginator->getLinks();
         d('links: ' . $pagerLinks);
     }
     $questions = \tplUquestions::loop($cursor);
//.........这里部分代码省略.........
开发者ID:codigoirreverente,项目名称:LampCMS,代码行数:101,代码来源:UserQuestions.php

示例7: getAnswers

 /**
  * Get html div with answers for this one question,
  * sorted according to param passed in request
  *
  * Enclose result in <div> and add pagination to bottom
  * of div if there is any pagination necessary!
  * 
  * @todo add skip() and limit() to cursor
  * in order to use pagination. 
  *
  * @param Question $Question
  *
  * @param string desired format of result. Possible
  * options are: html, array or json object
  * This will be useful for when we have an API
  *
  *
  * @return string html block
  */
 public function getAnswers(Question $Question, $result = 'html')
 {
     $Tr = $this->Registry->Tr;
     $qid = $Question['_id'];
     $url = $Question['url'];
     d('url: ' . $url);
     d('_GET: ' . print_r($_GET, 1));
     $cond = $this->Registry->Request->get('sort', 's', 'i_lm_ts');
     d('cond: ' . $cond);
     $noComments = false === (bool) $this->Registry->Ini->MAX_COMMENTS;
     d('no comments: ' . $noComments);
     $aFields = $noComments || false === (bool) $this->Registry->Ini->SHOW_COMMENTS ? array('comments' => 0) : array();
     /**
      * Extra security validation,
      * IMPORTANT because we should never use
      * anything in Mongo methods directly from
      * user input
      */
     if (!in_array($cond, array('i_ts', 'i_votes', 'i_lm_ts'))) {
         throw new Exception('invalid value of param "cond" was: ' . $cond);
     }
     $where = array('i_qid' => $qid);
     if (!$this->Registry->Viewer->isModerator()) {
         d('not moderator');
         $where['i_del_ts'] = null;
     }
     switch ($cond) {
         case 'i_ts':
             $sort = array('i_ts' => 1);
             break;
         case 'i_votes':
             $sort = array('i_votes' => -1);
             break;
         default:
             $sort = array($cond => -1);
     }
     $cursor = $this->Registry->Mongo->ANSWERS->find($where, $aFields);
     d('$cursor: ' . gettype($cursor));
     $cursor->sort($sort);
     $oPager = Paginator::factory($this->Registry);
     $oPager->paginate($cursor, $this->Registry->Ini->PER_PAGE_ANSWERS, array('path' => $this->Registry->Ini->SITE_URL . '/q' . $qid . '/' . $url . '/' . $cond, 'append' => false));
     //, 'fileName' => '&pageID=%d'
     $pagerLinks = $oPager->getLinks();
     $func = null;
     $ownerId = $Question['i_uid'];
     $showLink = $ownerId > 0 && ($this->Registry->Viewer->isModerator() || $ownerId == $this->Registry->Viewer->getUid());
     d('adding accept link callback function');
     /**
      * @todo Translate strings
      */
     $accept = $Tr['Accept'];
     $alt = $Tr['Click to accept this as best answer'];
     $alt2 = $Tr['Owner of the question accepted this as best answer'];
     $noComments = $noComments ? ' nocomments' : '';
     $addcomment = $Tr['add comment'];
     $edited = $Tr['Edited'];
     $reply = $Tr['Reply'];
     $reply_t = $Tr['Reply to this comment'];
     $func = function (&$a) use($accept, $alt, $alt2, $addcomment, $reply, $reply_t, $edited, $showLink, $noComments) {
         /**
          * Don't show Accept link for
          * already accepted answer
          */
         if (!$a['accepted']) {
             if ($showLink) {
                 $a['accept_link'] = '<a class="accept ttt" title="' . $alt . '" href="/accept/' . $a['_id'] . '">' . $accept . '</a>';
             }
         } else {
             $a['accepted'] = '<img src="/images/accepted.png" alt="Best answer" class="ttt" title="' . $alt2 . '">';
         }
         $a['add_comment'] = $addcomment;
         $a['nocomments'] = $noComments;
         $a['reply'] = $reply;
         $a['reply_t'] = $reply_t;
         $a['edited'] = $edited;
     };
     /**
      * Create div with answers, append pagination links
      * to bottom and return the whole div block
      */
     $answers = \tplAnswer::loop($cursor, true, $func) . $pagerLinks;
//.........这里部分代码省略.........
开发者ID:netconstructor,项目名称:LampCMS,代码行数:101,代码来源:Answers.php


注:本文中的Paginator::factory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。