本文整理汇总了PHP中Illuminate\Pagination\Paginator::total方法的典型用法代码示例。如果您正苦于以下问题:PHP Paginator::total方法的具体用法?PHP Paginator::total怎么用?PHP Paginator::total使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Pagination\Paginator
的用法示例。
在下文中一共展示了Paginator::total方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getTotal
/**
* Get the total.
*
* @return int
*/
public function getTotal()
{
if ($this->paginator instanceof LengthAwarePaginator) {
return $this->paginator->total();
}
return $this->paginator->count();
}
示例2: getInstances
/**
* Grab the actual instances.
*
* @return mixed
*/
public function getInstances()
{
// First create the params object with stuff like search, sorting
$this->createParams();
// And finally grab the entities
if ($this->entity->list_template->paginate) {
// Pagination config is set: grab the current page
$this->pagination = $this->repo->paginate($this->entity->list_template->paginate, $this->params);
$this->count = $this->pagination->total();
return $this->pagination->items();
} else {
// Grab all entities of this kind from DB
$instances = $this->repo->listAll($this->params);
$this->count = sizeof($instances);
return $instances;
}
}
示例3: 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";
if ($this->canOrderby($this->orderby_field)) {
$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);
}
}
$limit = $this->limit ? $this->limit : 100000;
$current_page = $this->url->value('page' . $this->cid, 0);
$offset = max($current_page - 1, 0) * $limit;
$this->data = array_slice($this->source, $offset, $limit);
$this->total_rows = count($this->source);
$this->paginator = new LengthAwarePaginator($this->data, $this->total_rows, $limit, $current_page, ['path' => Paginator::resolveCurrentPath(), 'pageName' => "page" . $this->cid]);
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, ['*'], 'page' . $this->cid);
$this->data = $this->paginator;
$this->total_rows = $this->paginator->total();
} else {
$this->data = $this->query->get();
$this->total_rows = count($this->data);
}
break;
}
return $this;
}