本文整理汇总了PHP中Illuminate\Pagination\Paginator::resolveCurrentPage方法的典型用法代码示例。如果您正苦于以下问题:PHP Paginator::resolveCurrentPage方法的具体用法?PHP Paginator::resolveCurrentPage怎么用?PHP Paginator::resolveCurrentPage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Pagination\Paginator
的用法示例。
在下文中一共展示了Paginator::resolveCurrentPage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index(Request $request)
{
$letter = $request->input('letter');
if (!isset($letter) || !$letter) {
$projects = $this->projectsGateway->findFeaturedProjects();
Debugbar::info($projects);
$data = array('letter' => strtoupper($letter), 'projects' => $projects);
return view('projects', $data);
}
$projects = $this->projectsGateway->findProjectsByLetter($letter);
$paginator = new LengthAwarePaginator($projects['data'], $projects['total'], $projects['per_page'], Paginator::resolveCurrentPage(), ['path' => Paginator::resolveCurrentPath()]);
Debugbar::info($projects);
$data = array('letter' => strtoupper($letter), 'projects' => $projects['data'], 'paginator' => $paginator);
return view('projects_by_letter', $data);
}
示例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: paginate
public function paginate($perPage = 15, $columns = ['*'], $pageName = 'page', $page = null)
{
$page = $page ?: Paginator::resolveCurrentPage($pageName);
$total = $this->count();
$results = $this->forPage($page, $perPage);
return new LengthAwarePaginator($results, $total, $perPage, $page, ['path' => Paginator::resolveCurrentPath(), 'pageName' => $pageName]);
}
示例4: AllContents
/**
* 取得未删除的信息
*
* @return array
* @todo 数据量多时,查找属于指定分类,推荐位,标签三个的文章时使用redis集合交集处理,避免查询消耗。
*/
public function AllContents($search = [])
{
$prefix = \DB::getTablePrefix();
$currentQuery = $this->select(['article_main.*', 'users.name'])->leftJoin('users', 'article_main.user_id', '=', 'users.id')->leftJoin('article_classify_relation', 'article_main.id', '=', 'article_classify_relation.article_id')->leftJoin('article_classify', 'article_classify_relation.classify_id', '=', 'article_classify.id')->leftJoin('article_position_relation', 'article_main.id', '=', 'article_position_relation.article_id')->leftJoin('article_tag_relation', 'article_main.id', '=', 'article_tag_relation.article_id')->orderBy('article_main.id', 'desc')->where('article_main.is_delete', self::IS_DELETE_NO)->groupBy('article_main.id')->distinct();
if (isset($search['keyword']) && !empty($search['keyword'])) {
$currentQuery->where('article_main.title', 'like', "%{$search['keyword']}%");
}
if (isset($search['username']) && !empty($search['username'])) {
$currentQuery->where('article_main.user_id', $search['username']);
}
if (isset($search['classify']) && !empty($search['classify'])) {
$currentQuery->where('article_classify_relation.classify_id', $search['classify']);
}
if (isset($search['position']) && !empty($search['position'])) {
$currentQuery->where('article_position_relation.position_id', $search['position']);
}
if (isset($search['tag']) && !empty($search['tag'])) {
$currentQuery->where('article_tag_relation.tag_id', $search['tag']);
}
if (isset($search['timeFrom'], $search['timeTo']) and !empty($search['timeFrom']) and !empty($search['timeTo'])) {
$search['timeFrom'] = strtotime($search['timeFrom']);
$search['timeTo'] = strtotime($search['timeTo']);
$currentQuery->whereBetween('article_main.write_time', [$search['timeFrom'], $search['timeTo']]);
}
$total = count($currentQuery->get()->all());
$currentQuery->forPage($page = Paginator::resolveCurrentPage(), $perPage = self::PAGE_NUMS);
$result = $currentQuery->get()->all();
return new LengthAwarePaginator($result, $total, $perPage, $page, ['path' => Paginator::resolveCurrentPath()]);
}
示例5: paginate
/**
* Return the paginated dataset of the underlying database.
*
* @param int $perPage
* @param array $columns
* @param string $pageName
* @param int $page
*
* @return \Illuminate\Pagination\Paginator
*/
public function paginate($perPage, $columns, $pageName, $page)
{
$total = count($this->db);
$page = $page ?: Paginator::resolveCurrentPage($pageName);
$results = array_slice($this->get(), ($page - 1) * $perPage, $perPage);
return new LengthAwarePaginator($results, $total, $perPage, $page, ['path' => Paginator::resolveCurrentPath(), 'pageName' => $pageName]);
}
示例6: paginateCollection
/**
* Paginates a collection. For simple pagination, one can override this function
*
* a little help from http://laravelsnippets.com/snippets/custom-data-pagination
*
* @param Collection $data
* @param int $perPage
* @param Request $request
* @param null $page
*
* @return LengthAwarePaginator
*/
public function paginateCollection(Collection $data, $perPage, Request $request, $page = null)
{
$pg = $request->get('page');
$page = $page ? (int) $page * 1 : (isset($pg) ? (int) $request->get('page') * 1 : 1);
$offset = $page * $perPage - $perPage;
return new LengthAwarePaginator($data->splice($offset, $perPage), $data->count(), $perPage, Paginator::resolveCurrentPage(), ['path' => Paginator::resolveCurrentPath()]);
}
示例7: feed
/**
* Список новостей
* @param Request $request
* @param null $alias
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function feed(Request $request, $alias = null)
{
$page = Paginator::resolveCurrentPage('page');
$per_page = config('paginator.per_page');
$category = Category::where('alias', $alias)->first();
$order_by = $request->input('order_by');
$articles = Article::whereRaw('1=1');
switch ($order_by) {
case 'name_desc':
$articles->orderBy('name', 'desc');
break;
case 'name_asc':
$articles->orderBy('name', 'asc');
break;
case 'date_desc':
$articles->orderBy('created_at', 'desc');
break;
case 'date_asc':
$articles->orderBy('created_at', 'asc');
break;
default:
$articles->orderBy('created_at', 'desc');
break;
}
if (is_null($category)) {
$articles = $articles->paginate($per_page);
} else {
$articles = $articles->where('category_id', $category->id)->paginate($per_page);
}
if ($order_by) {
$articles->appends('order_by', $order_by);
}
return view('pages/feed', ['articles' => $articles, 'category' => $category, 'page' => $page, 'order_by' => $order_by]);
}
示例8: show
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($projectId, $versionId, $id, Request $request)
{
$w = $request->input('w', self::ASC);
if (!$w || strcmp("", trim($w)) === 0 || !in_array(trim($w), [self::ASC, self::DESC]) || strcmp(sprintf("%d", self::DESC), trim($w)) === 0) {
$w = self::ASC;
} else {
$w = self::DESC;
}
//$o = $request->input('o', /* only option*/ 3);
$o = 3;
$version = $this->versionsGateway->findById($versionId);
$project = $version['project_artifact'];
Debugbar::info($version);
// $testRuns = $this->testRunsGateway->findByVersionId($version['id']);
// Debugbar::info($testRuns);
$testRun = $this->testRunsGateway->findById($id, $o, $w);
Debugbar::info($testRun);
$tests = $testRun['tests'];
Debugbar::info($tests);
$paginator = new LengthAwarePaginator($tests['data'], $tests['total'], $tests['per_page'], Paginator::resolveCurrentPage(), ['path' => Paginator::resolveCurrentPath(), 'query' => ["o" => $o, "w" => $w]]);
Debugbar::info($paginator);
$letter = strtoupper($project['name'][0]);
$user = $testRun['user'];
$data = array('projectId' => $projectId, 'versionId' => $versionId, 'version' => $version, 'project' => $project, 'id' => $id, 'testRun' => $testRun, 'letter' => $letter, 'user' => $user, 'tests' => $tests['data'], 'paginator' => $paginator, 'w' => $w);
return view('test_run', $data);
}
示例9: createPaginator
/**
* create aLengthAwarePaginator from an Eloquent Request
* This is useful because Laravel 5 only provide a simple paginator
* out of the box.
*
* @param $builder
* @param $perPage
* @return LengthAwarePaginator
*/
function createPaginator($builder, $perPage)
{
$page = Paginator::resolveCurrentPage();
$builder->skip(($page - 1) * $perPage)->take($perPage + 1);
$queryClone = clone $builder->getQuery();
$total = $queryClone->skip(0)->take($perPage + 1)->count();
return new LengthAwarePaginator($builder->get(), $total, $perPage, $page, ['path' => Paginator::resolveCurrentPath()]);
}
示例10: 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']);
}
示例11: paginate
/**
* Create paginator
*
* @param array $items
* @param int $perPage
* @return LengthAwarePaginator
*/
public function paginate($items, $perPage)
{
$pageStart = \Request::get('page', 1);
// Start displaying items from this number;
$offSet = $pageStart * $perPage - $perPage;
// Get only the items you need using array_slice
$itemsForCurrentPage = array_slice($items, $offSet, $perPage, true);
return new LengthAwarePaginator($itemsForCurrentPage, count($items), $perPage, Paginator::resolveCurrentPage(), array('path' => Paginator::resolveCurrentPath()));
}
示例12: paginate
public function paginate($perPage = 15, $columns = array('*'))
{
$this->model->underlyingQuery()->orderBy('created_at', 'desc')->orderBy('id', 'desc');
$perPage = $perPage ?: $this->entriesPerPage();
$pageName = 'page';
$query = $this->model->underlyingQuery();
$total = $query->getQuery()->getCountForPagination();
$query->forPage($page = Paginator::resolveCurrentPage($pageName), $perPage = $perPage ?: $this->model->model->getPerPage());
return new UpdatesPaginator($query->get($columns), $total, $perPage, $page, ['path' => Paginator::resolveCurrentPath(), 'pageName' => $pageName]);
}
示例13: scopeDistinctPaginate
/**
* A custom paginate method for when using the distinct() method. This fixes the incorrect 'total' reported by the default paginate.
* @param $query
* @param int $perPage
* @param array $columns
* @param string $pageName
* @return \Illuminate\Pagination\LengthAwarePaginator
*/
public function scopeDistinctPaginate($query, $perPage = 15, $columns = ['*'], $pageName = 'page')
{
// Get the results
$results = $query->forPage(Input::get($pageName, 1), $perPage)->get($columns);
// Now do a count on an unlimited version of the previous query
$query->limit(static::count())->offset(0);
$count = DB::select("SELECT COUNT(*) FROM (" . $query->toSql() . ") src;", $query->getBindings())[0]->{"COUNT(*)"};
// Create the paginator
return new LengthAwarePaginator($results, $count, $perPage, Paginator::resolveCurrentPage(), ['path' => Paginator::resolveCurrentPath()]);
}
示例14: show
/**
* Show feeds from a specific provider
*
* @param $provider_id
* @param Request $request
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function show($provider_id, Request $request)
{
$feedsPerPage = 10;
$page = $request->has('page') ? $request->get('page') : 1;
$provider = Provider::findOrFail($provider_id);
$feedArray = $this->createFeedsFromProvider($provider, $request->get('srch-term'));
$pageFeedArray = array_slice($feedArray, ($page - 1) * $feedsPerPage, ($page - 1) * $feedsPerPage + $feedsPerPage);
$paginator = new LengthAwarePaginator($pageFeedArray, count($feedArray), $feedsPerPage, Paginator::resolveCurrentPage(), ['path' => Paginator::resolveCurrentPath()]);
return view('providers.show', compact('provider', 'paginator'));
}
示例15: buildHtmlTitleCallback
/**
* Build HTML::title() callback.
*
* @param \Illuminate\Contracts\Foundation\Application $app
*
* @return callable
*/
protected function buildHtmlTitleCallback(Application $app)
{
return function ($title = null) use($app) {
$title = $title ?: trim(get_meta('title', ''));
$page = Paginator::resolveCurrentPage();
$data = ['site' => ['name' => memorize('site.name')], 'page' => ['title' => $title, 'number' => $page]];
$data['site']['name'] = $this->getHtmlTitleFormatForSite($data);
$output = $this->getHtmlTitleFormatForPage($data);
return $app->make('html')->create('title', trim($output));
};
}