本文整理汇总了PHP中Illuminate\Pagination\LengthAwarePaginator类的典型用法代码示例。如果您正苦于以下问题:PHP LengthAwarePaginator类的具体用法?PHP LengthAwarePaginator怎么用?PHP LengthAwarePaginator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LengthAwarePaginator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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'));
}
示例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();
}
示例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);
}
示例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;
}
示例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());
}
示例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;
}
示例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']);
}
示例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;
}
示例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);
}
示例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'));
}
示例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()];
}
示例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'));
}
示例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";
}
}