本文整理汇总了PHP中Illuminate\Pagination\LengthAwarePaginator::setPath方法的典型用法代码示例。如果您正苦于以下问题:PHP LengthAwarePaginator::setPath方法的具体用法?PHP LengthAwarePaginator::setPath怎么用?PHP LengthAwarePaginator::setPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Pagination\LengthAwarePaginator
的用法示例。
在下文中一共展示了LengthAwarePaginator::setPath方法的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: 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);
}
示例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: 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;
}
示例5: getIndex
public function getIndex(Request $request)
{
$sort = !is_null($request->input('sort')) ? $request->input('sort') : '';
$order = !is_null($request->input('order')) ? $request->input('order') : 'asc';
// End Filter sort and order for query
// Filter Search for query
$filter = !is_null($request->input('search')) ? '' : '';
$page = $request->input('page', 1);
$params = array('page' => $page, 'limit' => !is_null($request->input('rows')) ? filter_var($request->input('rows'), FILTER_VALIDATE_INT) : static::$per_page, 'sort' => $sort, 'order' => $order, 'params' => $filter, 'global' => isset($this->access['is_global']) ? $this->access['is_global'] : 0);
// Get Query
$results = $this->model->getRows($params);
// Build pagination setting
$page = $page >= 1 && filter_var($page, FILTER_VALIDATE_INT) !== false ? $page : 1;
$pagination = new Paginator($results['rows'], $results['total'], $params['limit']);
$pagination->setPath('esireport');
$this->data['rowData'] = $results['rows'];
// Build Pagination
$this->data['pagination'] = $pagination;
// Build pager number and append current param GET
$this->data['pager'] = $this->injectPaginate();
// Row grid Number
$this->data['i'] = $page * $params['limit'] - $params['limit'];
// Grid Configuration
$this->data['tableGrid'] = $this->info['config']['grid'];
$this->data['tableForm'] = $this->info['config']['forms'];
$this->data['colspan'] = \SiteHelpers::viewColSpan($this->info['config']['grid']);
// Group users permission
$this->data['access'] = $this->access;
// Detail from master if any
// Master detail link if any
$this->data['subgrid'] = isset($this->info['config']['subgrid']) ? $this->info['config']['subgrid'] : array();
// Render into template
return view('esireport.index', $this->data);
}
示例6: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
$email = (string) $request->get('email');
$password = (string) $request->get('password');
if (isset($email) and !empty($email) and isset($password) and !empty($password)) {
if ($email === "user@codepi.com" and $password === "pwd2015") {
$user = User::where('email', '=', $email)->count();
if ($user == 0) {
User::create(['email' => $email, 'password' => Hash::make($password)]);
}
if (Auth::attempt(['email' => $email, 'password' => $password])) {
//$items = Concert::all()->toArray();
$query = 'select * from concerts';
$items = DB::select(DB::raw($query));
$perPage = 20;
$page = Input::get('page') ? Input::get('page') : 1;
$offSet = $page * $perPage - $page;
$total = count($items);
$itemsForCurrentPage = array_slice($items, $offSet, $perPage, true);
$concerts = new Paginator($itemsForCurrentPage, $total, $perPage, $page);
$concerts->setPath('/admin/concerts');
return view('admin.admin-concerts-page', ['concerts' => $concerts]);
}
return view('admin.auth-page');
}
return view('admin.auth-page');
}
return view('admin.auth-page');
}
示例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: 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;
}
示例10: 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'));
}
示例11: 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'));
}
示例12: 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'));
}
示例13: 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";
}
}
示例14: 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;
}
示例15: 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'));
}