• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Pagination\LengthAwarePaginator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Illuminate\Pagination\LengthAwarePaginator的典型用法代码示例。如果您正苦于以下问题:PHP LengthAwarePaginator类的具体用法?PHP LengthAwarePaginator怎么用?PHP LengthAwarePaginator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: page

 public static function page($collection, $perPage, $path = '')
 {
     //获取分页 的页码
     //        $currentPage=0;
     //        if(@$_SERVER['REQUEST_URI']){
     //            $page=explode("=",$_SERVER['REQUEST_URI']);
     //            if(isset($page[1])) {
     //                $currentPage = $page[1];
     //            }
     //        }else{
     //            $currentPage=0;
     //        }
     $page = LengthAwarePaginator::resolveCurrentPage();
     $currentPage = $page - 1;
     $currentPage < 0 ? $currentPage = 0 : '';
     //        echo $currentPage;
     //创建一个新的数组集合
     $collection = new Collection($collection);
     //获取分页的数据
     $currentPageSearchResults = $collection->slice($currentPage * $perPage, $perPage)->all();
     //创建一个新的分页模块
     $paginator = new LengthAwarePaginator($currentPageSearchResults, count($collection), $perPage);
     //获取分页path
     $url = Request::path();
     $path ? $path : $url;
     //设置分页的path
     $paginator->setPath($path);
     return $paginator;
 }
开发者ID:liuxue5213,项目名称:laravel,代码行数:29,代码来源:ShareFun.php


示例2: getPaginatedEntries

 /**
  * Returns the entries for the current page for this view.
  *
  * @return \Illuminate\Pagination\LengthAwarePaginator paginator containing the entries for the page, sorted/ordered or not.
  */
 public function getPaginatedEntries()
 {
     // Gets all the entries, sensitive to whether we're sorting for this request.
     $allEntries = $this->getEntriesSortable();
     $page = Paginator::resolveCurrentPage('page');
     // Returns the number of entries perpage, defined by Model#getPerPage
     $perPage = $allEntries->first()->getPerPage();
     // If the page number is beyond the number of pages, get it back to the last page.
     while (($page - 1) * $perPage > count($allEntries)) {
         $page -= 1;
     }
     // Return the subset of the entries for this page
     $entriesForPage = $allEntries->splice(($page - 1) * $perPage, $perPage);
     // Return the paginator for this subset.
     $entriesPaginator = new LengthAwarePaginator($entriesForPage, $this->getEntries()->first()->toBase()->getCountForPagination(), $perPage, $page, ['path' => Paginator::resolveCurrentPath(), 'pageName' => 'page']);
     // If we're ordering, append that to the links
     if ($this->getSortOrder()) {
         $entriesPaginator->appends(['order' => Request::get('order')]);
     }
     // If we're sorting, append that to the links
     if ($this->isSorting()) {
         $entriesPaginator->appends(['sort' => $this->getSortKey()]);
     }
     return $entriesPaginator;
 }
开发者ID:uidaho,项目名称:squireproject,代码行数:30,代码来源:PaginatedRequest.php


示例3: index

 /**
  * Ce controller à pour but de gérer la logique de recherche d'un film dans la base de données
  * Le controller gère aussi les topics lorsque l'utilisateur fait une recherche via les checkboxes sur
  * la page de d'affichage des résultats.
  * Les fonctions paginate servent à créer le paginator qui est simplement l'affichage des films 20 par 20.
  *
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $search = Input::get('search');
     $topics = Input::except('search', 'page');
     if (empty($topics)) {
         // Pas de topics on renvoie simplement les films correspondants
         $allMovies = Movies::where('title', 'like', "%{$search}%")->paginate(20)->appends(Input::except('page'));
     } else {
         // SI on a des topics dans l'input il est nécessaire de filtrer
         $movies = Topics::whereIn('topic_name', $topics)->with('movies')->get();
         $moviesCollection = Collection::make();
         foreach ($movies as $movy) {
             $moviesCollection->add($movy->movies()->where('title', 'like', "%{$search}%")->get());
         }
         $moviesCollection = $moviesCollection->collapse();
         // Il n'est pas possible de créer la paginator directement, on le crée donc à la main
         $page = Input::get('page', 1);
         $perPage = 20;
         $offset = $page * $perPage - $perPage;
         $allMovies = new LengthAwarePaginator($moviesCollection->slice($offset, $perPage, true), $moviesCollection->count(), $perPage);
         $allMovies->setPath(Paginator::resolveCurrentPath());
         $allMovies->appends(Input::except('page'));
     }
     // A la vue correspondante on lui renvoie une liste des films correspondants à la recherche, le tout paginé
     return view('search', compact('allMovies'));
 }
开发者ID:Tirke,项目名称:ShortMovies,代码行数:35,代码来源:SearchController.php


示例4: createPagedCollection

 protected function createPagedCollection(LengthAwarePaginator $paginator, TransformerAbstract $transformer)
 {
     $data = $paginator->getCollection();
     $collection = new Collection($data, $transformer);
     $collection->setPaginator(new IlluminatePaginatorAdapter($paginator));
     return $this->fractal->createData($collection)->toArray();
 }
开发者ID:Gamespectre,项目名称:spectator-api,代码行数:7,代码来源:FractalDataTrait.php


示例5: pesok

 public function pesok()
 {
     $category = Category::where('sef', '=', 'catalogs')->first();
     $path = explode("?", substr($_SERVER['REQUEST_URI'], 1));
     $link = Link::where('url', $path[0])->first();
     // удалить первый слеш из URI и вернуть строку до первого вхождения знака ?
     // иначе на второй и следующей странице пагинации переменная $link будет содержать всякий хлам
     // типа ?page=4 и естесственно в БД такой ссылки не найдется
     $img = File::allFiles(public_path() . '/img/risunki/pesok');
     // pagination нашел тута  http://psampaz.github.io/custom-data-pagination-with-laravel-5/
     //Get current page form url e.g. &page=6
     $currentPage = LengthAwarePaginator::resolveCurrentPage();
     if (is_null($currentPage)) {
         $currentPage = 1;
     }
     //Create a new Laravel collection from the array data
     $collection = new Collection($img);
     //Define how many items we want to be visible in each page
     $perPage = 20;
     //Slice the collection to get the items to display in current page
     $currentPageImgResults = $collection->slice(($currentPage - 1) * $perPage, $perPage)->all();
     //Create our paginator and pass it to the view
     $paginatedImgResults = new LengthAwarePaginator($currentPageImgResults, count($collection), $perPage);
     $paginatedImgResults->setPath('peskostrujnie-risunki');
     return view('links.pesok')->withCategory($category)->withLink($link)->withImg($paginatedImgResults)->withPath($path);
 }
开发者ID:schel4ok,项目名称:steklo,代码行数:26,代码来源:FileController.php


示例6: response

 /**
  * @param $results
  * @param $with
  * @param $paginated
  * @param Searchable|null $model
  * @return array|LengthAwarePaginator
  */
 protected function response($results, $with, $paginated, Searchable $model = null)
 {
     $collection = $this->asModels($results['hits']['hits'], $model);
     /*
      * if we also want to lazy load relations, we'll create a collection and load them,
      * pass them on to the paginator if needed
      * heads up: i believe nested documents will always be loaded,
      * so developer should only pass with relations that aren't being indexed by Elasticsearch
      */
     if ($with) {
         $model->unguard();
         $collection = $model->newCollection($collection);
         $model->reguard();
         $collection->load($with);
     }
     if ($paginated) {
         /*
          * if we lazy loaded some relations, we need to get back an array to paginate.
          * not an optimal way of doing this, but i believe there isn't a better way at this point,
          * since the paginator only takes an array.
          */
         $collection = is_array($collection) ? $collection : $collection->all();
         $path = Paginator::resolveCurrentPath();
         //for some reason things do not work when passing in the options as an regular array
         $results = new LengthAwarePaginator($collection, $results['hits']['total'], $paginated);
         $results->setPath($path);
         //only need transform into a collection when we didn't lazyload relations
     } elseif (is_array($collection)) {
         $results = $model->newCollection($collection);
     } else {
         $results = $collection;
     }
     return $results;
 }
开发者ID:jaffle-be,项目名称:framework,代码行数:41,代码来源:SearchResponder.php


示例7: paginate

 /**
  * Paginate log entries.
  *
  * @param  int  $perPage
  *
  * @return \Illuminate\Pagination\LengthAwarePaginator
  */
 public function paginate($perPage = 20)
 {
     $request = request();
     $page = $request->input('page', 1);
     $paginator = new LengthAwarePaginator($this->slice($page * $perPage - $perPage, $perPage), $this->count(), $perPage, $page);
     return $paginator->setPath($request->url());
 }
开发者ID:vjandrea,项目名称:LogViewer,代码行数:14,代码来源:LogEntryCollection.php


示例8: paginate

 /**
  * Paginate log entries.
  *
  * @param  int  $perPage
  *
  * @return LengthAwarePaginator
  */
 public function paginate($perPage = 20)
 {
     $page = request()->input('page', 1);
     $items = $this->slice($page * $perPage - $perPage, $perPage, true);
     $paginator = new LengthAwarePaginator($items, $this->count(), $perPage, $page);
     $paginator->setPath(request()->url());
     return $paginator;
 }
开发者ID:janusnic,项目名称:LogViewer,代码行数:15,代码来源:LogEntryCollection.php


示例9: paginate

 /**
  * Paginates the Elasticsearch results.
  *
  * @param int $perPage
  * @return mixed
  */
 public function paginate($perPage = 15)
 {
     $page = Paginator::resolveCurrentPage('page');
     $paginator = new LengthAwarePaginator($this->items, $this->total(), $perPage, $page);
     $start = ($paginator->currentPage() - 1) * $perPage;
     $sliced = array_slice($this->items, $start, $perPage);
     return new LengthAwarePaginator($sliced, $this->total(), $perPage, $page, ['path' => Paginator::resolveCurrentPath(), 'pageName' => 'page']);
 }
开发者ID:mozzos,项目名称:bouncy,代码行数:14,代码来源:ElasticCollection.php


示例10: createPaginator

 /**
  * @param Collection $originalData
  * @return LengthAwarePaginator
  */
 protected function createPaginator($originalData)
 {
     $perPage = property_exists($this, 'perPage') ? $this->perPage : 10;
     $paginatorPath = property_exists($this, 'paginatorPath') ? $this->paginatorPath : '/';
     $currentPage = request()->query('page', 1);
     $p = new LengthAwarePaginator($originalData->forPage($currentPage, $perPage), count($originalData), $perPage);
     $p->setPath($paginatorPath);
     return $p;
 }
开发者ID:hungphongbk,项目名称:ulibi,代码行数:13,代码来源:PaginateContent.php


示例11: respondWithPaginator

 /**
  * @param Paginator $data
  * @param TransformerAbstract $transformer
  * @param array $headers
  * @return \Illuminate\Http\JsonResponse
  */
 public function respondWithPaginator(LengthAwarePaginator $data, TransformerAbstract $transformer, $headers = [])
 {
     $manager = new Manager();
     $manager->setSerializer(new ArraySerializer());
     $resource = new Collection($data->getCollection(), $transformer);
     $resource->setPaginator(new IlluminatePaginatorAdapter($data));
     $response = $manager->createData($resource)->toArray();
     return $this->respond(['post' => $this->_request->all(), 'data' => $response['data'], 'meta' => $response['meta'], 'error' => ['global' => '']], $headers);
 }
开发者ID:Buuntu,项目名称:Laravel-API,代码行数:15,代码来源:ApiController.php


示例12: index

 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $page = Input::get('page', 1);
     $perPage = 10;
     $pagiData = $this->news->paginate($page, $perPage, true);
     $news = new LengthAwarePaginator($pagiData->items, $pagiData->totalItems, $perPage, ['path' => Paginator::resolveCurrentPath()]);
     $news->setPath("");
     return view('backend.news.index', compact('news'));
 }
开发者ID:RudolfFussek,项目名称:fullycms,代码行数:14,代码来源:NewsController.php


示例13: getData

 /**
  * Get data .
  *
  * @param null $perPage
  * @return array
  */
 public function getData($perPage = null)
 {
     $source = $this->getSource();
     $items = $source['rows'];
     $offSet = @$_GET['page'] * $perPage - $perPage;
     $itemsForCurrentPage = array_slice($items, $offSet, $perPage, true);
     $paginator = new LengthAwarePaginator($itemsForCurrentPage, count($source['rows']), $perPage);
     return ['columns' => $this->source['columns'], 'rows' => $paginator->getCollection(), 'total' => $paginator->total()];
 }
开发者ID:parfumix,项目名称:table-manager,代码行数:15,代码来源:Collection.php


示例14: index

 /**
  * Display videos page
  * @param $id
  * @return \Illuminate\View\View
  */
 public function index()
 {
     //$videos = $this->video->paginate();
     $page = Input::get('page', 1);
     $perPage = 12;
     $pagiData = $this->video->paginate($page, $perPage, false);
     $videos = new LengthAwarePaginator($pagiData->items, $pagiData->totalItems, $perPage, ['path' => Paginator::resolveCurrentPath()]);
     $videos->setPath("");
     return view('frontend.video.index', compact('videos'));
 }
开发者ID:phillipmadsen,项目名称:deved,代码行数:15,代码来源:VideoController.php


示例15: display

 /**
  * Display repeater view
  * @param string $content
  * @param array $options
  * @return string
  */
 public function display($content, $options = [])
 {
     $repeaterId = $content;
     $template = !empty($options['view']) ? $options['view'] : $this->_block->name;
     $repeatersViews = 'themes.' . PageBuilder::getData('theme') . '.blocks.repeaters.';
     if (!empty($options['form'])) {
         return FormWrap::view($this->_block, $options, $repeatersViews . $template . '-form');
     }
     if (View::exists($repeatersViews . $template)) {
         $renderedContent = '';
         if ($repeaterBlocks = BlockRepeater::getRepeaterBlocks($this->_block->id)) {
             $random = !empty($options['random']) ? $options['random'] : false;
             $repeaterRows = PageBlockRepeaterData::loadRepeaterData($repeaterId, $options['version'], $random);
             // pagination
             if (!empty($options['per_page']) && !empty($repeaterRows)) {
                 $pagination = new LengthAwarePaginator($repeaterRows, count($repeaterRows), $options['per_page'], Request::input('page', 1));
                 $pagination->setPath(Request::getPathInfo());
                 $paginationLinks = PaginatorRender::run($pagination);
                 $repeaterRows = array_slice($repeaterRows, ($pagination->currentPage() - 1) * $options['per_page'], $options['per_page'], true);
             } else {
                 $paginationLinks = '';
             }
             if (!empty($repeaterRows)) {
                 $i = 1;
                 $isFirst = true;
                 $isLast = false;
                 $rows = count($repeaterRows);
                 $cols = !empty($options['cols']) ? (int) $options['cols'] : 1;
                 $column = !empty($options['column']) ? (int) $options['column'] : 1;
                 foreach ($repeaterRows as $rowId => $row) {
                     if ($i % $cols == $column % $cols) {
                         $previousKey = PageBuilder::getCustomBlockDataKey();
                         PageBuilder::setCustomBlockDataKey('repeater' . $repeaterId . '.' . $rowId);
                         foreach ($repeaterBlocks as $repeaterBlock) {
                             if ($repeaterBlock->exists) {
                                 PageBuilder::setCustomBlockData($repeaterBlock->name, !empty($row[$repeaterBlock->id]) ? $row[$repeaterBlock->id] : '', null, false);
                             }
                         }
                         if ($i + $cols - 1 >= $rows) {
                             $isLast = true;
                         }
                         $renderedContent .= View::make($repeatersViews . $template, array('is_first' => $isFirst, 'is_last' => $isLast, 'count' => $i, 'total' => $rows, 'id' => $repeaterId, 'pagination' => $paginationLinks, 'links' => $paginationLinks))->render();
                         $isFirst = false;
                         PageBuilder::setCustomBlockDataKey($previousKey);
                     }
                     $i++;
                 }
             }
         }
         return $renderedContent;
     } else {
         return "Repeater view does not exist in theme";
     }
 }
开发者ID:web-feet,项目名称:coasterframework,代码行数:60,代码来源:Repeater.php


示例16: listLogs

 public function listLogs()
 {
     $stats = $this->logViewer->statsTable();
     $headers = $stats->header();
     // $footer   = $stats->footer();
     $page = request('page', 1);
     $offset = $page * $this->perPage - $this->perPage;
     $rows = new LengthAwarePaginator(array_slice($stats->rows(), $offset, $this->perPage, true), count($stats->rows()), $this->perPage, $page);
     $rows->setPath(request()->url());
     return $this->view('logs', compact('headers', 'rows', 'footer'));
 }
开发者ID:pnagaraju25,项目名称:LogViewer,代码行数:11,代码来源:LogViewerController.php


示例17: make

 /**
  * 给一个分页对象, 设置当前url, 及query参数
  * @param LengthAwarePaginator $p
  * @param array $options
  * @return LengthAwarePaginator
  */
 public static function make($p, $options = [])
 {
     $query = array_get($options, 'query', function () {
         return Request::getFacadeRoot()->query->all();
     });
     foreach ($query as $key => $value) {
         $p->addQuery($key, $value);
     }
     $p->setPath(array_get($options, 'path', URL::current()));
     return $p;
 }
开发者ID:windqyoung,项目名称:utils,代码行数:17,代码来源:PageCur.php


示例18: index

 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $page = Input::get('page', 1);
     $perPage = 5;
     $pagiData = $this->article->paginate($page, $perPage, false);
     $articles = new LengthAwarePaginator($pagiData->items, $pagiData->totalItems, $perPage, ['path' => Paginator::resolveCurrentPath()]);
     $articles->setPath("");
     $tags = $this->tag->all();
     $categories = $this->category->all();
     return view('frontend.article.index', compact('articles', 'tags', 'categories'));
 }
开发者ID:phillipmadsen,项目名称:app,代码行数:16,代码来源:ArticleController.php


示例19: __construct

 /**
  * Constructor.
  * @param Collection|LengthAwarePaginator $collection
  * @param string $class - optional
  */
 public function __construct($collection, $class = null)
 {
     if ($collection instanceof LengthAwarePaginator) {
         $this->paginator = $collection;
         $this->items = $collection->getCollection();
     } else {
         $this->items = $collection;
     }
     if ($class) {
         $this->setClass($class);
     }
 }
开发者ID:breachofmind,项目名称:birdmin,代码行数:17,代码来源:Table.php


示例20: afterLoad

 public function afterLoad()
 {
     $linkedWidget = $this->widgetManager->getWidgetById($this->linked_widget_id);
     $paginator = null;
     if (!is_null($linkedWidget) and $linkedWidget instanceof WidgetPaginator) {
         $paginator = new LengthAwarePaginator([], $linkedWidget->getTotalDocuments(), $linkedWidget->list_size);
         $paginator->setPageName($this->query_key);
         $paginator->setPath(Request::path());
         $linkedWidget->list_offset = (int) (($paginator->currentPage() - 1) * $paginator->perPage());
     }
     $this->paginator = $paginator;
 }
开发者ID:KodiComponents,项目名称:module-widgets,代码行数:12,代码来源:Paginator.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Pagination\Paginator类代码示例发布时间:2022-05-23
下一篇:
PHP Pagination\Factory类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap