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


PHP Paginator::getFrom方法代码示例

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


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

示例1: paginator

 public function paginator(\Illuminate\Pagination\Paginator &$paginator)
 {
     $items = [];
     foreach ($this as $index => $item) {
         if ($index < $paginator->getFrom() - 1 || $index > $paginator->getTo() - 1) {
             continue;
         }
         $items[] = $item;
     }
     $paginator->setItems($items);
     return $paginator;
 }
开发者ID:itvisionsy,项目名称:laravel-extras,代码行数:12,代码来源:Collection.php

示例2: build

 public function build()
 {
     if (is_string($this->source) && strpos(" ", $this->source) === false) {
         //tablename
         $this->type = "query";
         $this->query = $this->table($this->source);
     } elseif (is_a($this->source, "\\Illuminate\\Database\\Eloquent\\Model")) {
         $this->type = "model";
         $this->query = $this->source;
         $this->key = $this->source->getKeyName();
     } elseif (is_a($this->source, "\\Illuminate\\Database\\Eloquent\\Builder")) {
         $this->type = "model";
         $this->query = $this->source;
         $this->key = $this->source->getModel()->getKeyName();
     } elseif (is_a($this->source, "\\Illuminate\\Database\\Query\\Builder")) {
         $this->type = "model";
         $this->query = $this->source;
     } elseif (is_a($this->source, "\\Zofe\\Rapyd\\DataFilter\\DataFilter")) {
         $this->type = "model";
         $this->query = $this->source->query;
         if (is_a($this->query, "\\Illuminate\\Database\\Eloquent\\Model")) {
             $this->key = $this->query->getKeyName();
         } elseif (is_a($this->query, "\\Illuminate\\Database\\Eloquent\\Builder")) {
             $this->key = $this->query->getModel()->getKeyName();
         }
     } elseif (is_array($this->source)) {
         $this->type = "array";
     } else {
         throw new DataSetException(' "source" must be a table name, an eloquent model or an eloquent builder. you passed: ' . get_class($this->source));
     }
     //build orderby urls
     $this->orderby_uri_asc = $this->url->remove('page' . $this->cid)->remove('reset' . $this->cid)->append('ord' . $this->cid, "-field-")->get() . $this->hash;
     $this->orderby_uri_desc = $this->url->remove('page' . $this->cid)->remove('reset' . $this->cid)->append('ord' . $this->cid, "--field-")->get() . $this->hash;
     //detect orderby
     $orderby = $this->url->value("ord" . $this->cid);
     if ($orderby) {
         $this->orderby_field = ltrim($orderby, "-");
         $this->orderby_direction = $orderby[0] === "-" ? "desc" : "asc";
         $this->orderBy($this->orderby_field, $this->orderby_direction);
     }
     //build subset of data
     switch ($this->type) {
         case "array":
             //orderby
             if (isset($this->orderby)) {
                 list($field, $direction) = $this->orderby;
                 $column = array();
                 foreach ($this->source as $key => $row) {
                     $column[$key] = is_object($row) ? $row->{$field} : $row[$field];
                 }
                 if ($direction == "asc") {
                     array_multisort($column, SORT_ASC, $this->source);
                 } else {
                     array_multisort($column, SORT_DESC, $this->source);
                 }
             }
             // @TODO: must be refactored
             $this->paginator = Paginator::make($this->source, count($this->source), $this->limit ? $this->limit : 1000000);
             //find better way
             $this->data = array_slice($this->source, $this->paginator->getFrom() - 1, $this->limit);
             break;
         case "query":
         case "model":
             //orderby
             if (isset($this->orderby)) {
                 $this->query = $this->query->orderBy($this->orderby[0], $this->orderby[1]);
             }
             //limit-offset
             if (isset($this->limit)) {
                 $this->paginator = $this->query->paginate($this->limit);
                 $this->data = $this->paginator;
             } else {
                 $this->data = $this->query->get();
             }
             break;
     }
     return $this;
 }
开发者ID:parabol,项目名称:laravel-cms,代码行数:78,代码来源:DataSet.php


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