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


PHP Collection::slice方法代码示例

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


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

示例1: getInitial

 public function getInitial()
 {
     $words = new Collection(explode(' ', $this->name));
     // if name contains single word, use first N character
     if ($words->count() === 1) {
         if ($this->name->length() >= $this->length) {
             return $this->name->substr(0, $this->length);
         }
         return (string) $words->first();
     }
     // otherwise, use initial char from each word
     $initials = new Collection();
     $words->each(function ($word) use($initials) {
         $initials->push(Stringy::create($word)->substr(0, 1));
     });
     return $initials->slice(0, $this->length)->implode('');
 }
开发者ID:explore-laravel,项目名称:avatar,代码行数:17,代码来源:InitialGenerator.php

示例2: 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;
 }
开发者ID:liuxue5213,项目名称:laravel,代码行数:29,代码来源:ShareFun.php

示例3: 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);
 }
开发者ID:schel4ok,项目名称:steklo,代码行数:26,代码来源:FileController.php

示例4: internalMake

 protected function internalMake(Collection $columns, array $searchColumns = array())
 {
     $this->compileArray($columns);
     $this->doInternalSearch($columns, $searchColumns);
     $this->doInternalOrder();
     return $this->workingCollection->slice($this->skip, $this->limit);
 }
开发者ID:imihael,项目名称:datatable,代码行数:7,代码来源:CollectionEngine.php

示例5: characters

 public function characters(Request $request)
 {
     $characters = Cache::get('characters');
     $current_page = LengthAwarePaginator::resolveCurrentPage();
     if (is_null($current_page)) {
         $current_page = 1;
     }
     $characters_collection = new Collection($characters);
     $items_per_page = 8;
     $current_page_results = $characters_collection->slice(($current_page - 1) * $items_per_page, $items_per_page)->all();
     $paginated_results = new LengthAwarePaginator($current_page_results, count($characters_collection), $items_per_page);
     return view('characters', ['paginated_results' => $paginated_results, 'characters' => $characters]);
 }
开发者ID:anchetaWern,项目名称:marvel-viewer,代码行数:13,代码来源:HomeController.php

示例6: index

 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     FlashPlayerSession::Flash();
     $players = $teams = Auth::user()->players();
     $currentPage = LengthAwarePaginator::resolveCurrentPage();
     //Create a new Laravel collection from the array data
     $collection = new Collection($players);
     //Define how many items we want to be visible in each page
     $perPage = 10;
     //Slice the collection to get the items to display in current page
     $currentPageSearchResults = $collection->slice($currentPage * $perPage, $perPage)->all();
     //Create our paginator and pass it to the view
     $paginatedSearchResults = new LengthAwarePaginator($currentPageSearchResults, count($collection), $perPage);
     return view('frontend.ball.player.index', ['players' => $paginatedSearchResults]);
 }
开发者ID:faycal1,项目名称:Ball,代码行数:20,代码来源:PlayerController.php

示例7: getObras

 /**
  * Obtiene las obras de un usuario cadeco de todas las bases de datos definidas
  *
  * @param $idUsuario
  * @return Collection|Obra
  */
 public function getObras($idUsuario)
 {
     $obrasUsuario = new Collection();
     $basesDatos = BaseDatosCadeco::where('activa', true)->orderBy('nombre')->get();
     foreach ($basesDatos as $bd) {
         $this->config->set('database.connections.cadeco.database', $bd->nombre);
         $usuarioCadeco = $this->getUsuarioCadeco($idUsuario);
         $obras = $this->getObrasUsuario($usuarioCadeco);
         foreach ($obras as $obra) {
             $obra->databaseName = $bd->nombre;
             $obrasUsuario->push($obra);
         }
         DB::disconnect('cadeco');
     }
     $perPage = 10;
     $currentPage = Paginator::resolveCurrentPage();
     $currentPage = $currentPage ? $currentPage : 1;
     $offset = $currentPage * $perPage - $perPage;
     $paginator = new LengthAwarePaginator($obrasUsuario->slice($offset, $perPage), $obrasUsuario->count(), $perPage);
     return $paginator;
 }
开发者ID:Grupo-Hermes-Infraestructura,项目名称:core,代码行数:27,代码来源:EloquentUserRepository.php

示例8: getItem

 public function getItem($item)
 {
     $item = Page::where('sef', '=', $item)->first();
     //  $path = explode("?", substr($_SERVER['REQUEST_URI'], 1));
     //  $link = Page::where('sef', $path[0] )->first();
     $img = File::allFiles(public_path() . '/img/foto/' . $item->sef);
     $currentPage = LengthAwarePaginator::resolveCurrentPage();
     if (is_null($currentPage)) {
         $currentPage = 1;
     }
     $collection = new Collection($img);
     $perPage = 40;
     $currentPageImgResults = $collection->slice(($currentPage - 1) * $perPage, $perPage)->all();
     $paginatedImgResults = new LengthAwarePaginator($currentPageImgResults, count($collection), $perPage);
     $paginatedImgResults->setPath($item->sef);
     $previous = Page::where('id', '<', $item->id)->orderBy('id', 'desc')->first();
     $next = Page::where('id', '>', $item->id)->orderBy('id', 'asc')->first();
     $category = Category::where('id', $item->category_id)->first();
     // список всех ссылок для бокового меню
     $items = Page::where('category_id', $item->category_id)->get();
     return view('foto.item')->withCategory($category)->withItem($item)->withItems($items)->withImg($paginatedImgResults)->withPrevious($previous)->withNext($next);
 }
开发者ID:schel4ok,项目名称:steklo,代码行数:22,代码来源:ImageController.php

示例9: characters

 public function characters(Request $request)
 {
     $search_term = '';
     if ($request->has('query')) {
         $search_term = $request->input('query');
         $query = $this->client->getConfig('query');
         $query['nameStartsWith'] = $search_term;
         $response = $this->client->get('characters', ['query' => $query]);
         $response = json_decode($response->getBody(), true);
         $characters = $response['data']['results'];
     } else {
         $characters = Cache::get('characters');
     }
     $current_page = LengthAwarePaginator::resolveCurrentPage();
     if (is_null($current_page)) {
         $current_page = 1;
     }
     $characters_collection = new Collection($characters);
     $items_per_page = 8;
     $current_page_results = $characters_collection->slice(($current_page - 1) * $items_per_page, $items_per_page)->all();
     $paginated_results = new LengthAwarePaginator($current_page_results, count($characters_collection), $items_per_page);
     return view('characters', ['paginated_results' => $paginated_results, 'characters' => $characters, 'query' => $search_term]);
 }
开发者ID:anchetaWern,项目名称:marvel-viewer,代码行数:23,代码来源:ggController.php

示例10: paging

 /**
  * Perform pagination
  *
  * @return mixed
  */
 public function paging()
 {
     $this->collection = $this->collection->slice($this->request->getStart(), $this->request->getCount());
 }
开发者ID:mikelmi,项目名称:mks-smart-table,代码行数:9,代码来源:CollectionEngine.php

示例11: paging

 /**
  * @inheritdoc
  */
 public function paging()
 {
     $this->collection = $this->collection->slice($this->request['start'], (int) $this->request['length'] > 0 ? $this->request['length'] : 10);
 }
开发者ID:marcha,项目名称:laravel-datatables,代码行数:7,代码来源:CollectionEngine.php

示例12: processChunk

 /**
  * @param $fs Filesystem
  * @param $scrapers Collection
  **/
 protected function processChunk(Filesystem $fs, Collection $scrapers)
 {
     $lastJob = 0;
     if ($fs->exists('lastScraperRun')) {
         $lastJob = $fs->get('lastScraperRun');
     }
     $scrapers->slice($lastJob, self::JOBS_PER_CALL);
     $this->scheduleScrapers($scrapers);
     $nextJob = 0;
     if ($lastJob + self::JOBS_PER_CALL > $scrapers->count()) {
         $nextJob = $lastJob + self::JOBS_PER_CALL;
     }
     $fs->put('lastScraperRun', $nextJob);
 }
开发者ID:wasgeht-berlin,项目名称:website,代码行数:18,代码来源:DataScrapers.php

示例13: search

 public function search()
 {
     session_start();
     unset($_SESSION['contact_report_to']);
     //create a session for location
     $_SESSION['loc'] = "ticket";
     //creating objects
     $pagesettings = new functions\pagesettings();
     //get selected columns
     $selected_columns = $pagesettings->fname('ticket', '1');
     //get select columns names
     foreach ($selected_columns as $result) {
         $column_comment = $pagesettings->viewcolumncomment($result->column_name, 'ticket');
         foreach ($column_comment as $result_2) {
             $table_headings[] = $result_2->column_comment;
         }
     }
     $_SESSION['sort'] = "DESC";
     //get data for call log
     $result = $this->view_tickets_all(1000, 0);
     //Get current page form url e.g. &page=6
     $currentPage = LengthAwarePaginator::resolveCurrentPage();
     //pagination starting form 0. e.g. &page=1 mean page=0
     if ($currentPage != NULL) {
         $currentPage = $currentPage - 1;
     }
     //Create a new Laravel collection from the array data
     $collection = new Collection($result);
     //Define how many items we want to be visible in each page
     $perPage = 1000000;
     //Slice the collection to get the items to display in current page
     $currentPageSearchResults = $collection->slice($currentPage * $perPage, $perPage)->all();
     //Create our paginator and pass it to the view
     $result = new LengthAwarePaginator($currentPageSearchResults, count($collection), $perPage);
     //return this data to the view
     return View::make('ticket.ticket', compact('table_headings', 'selected_columns', 'result'));
 }
开发者ID:sandakinhs,项目名称:iCRM3,代码行数:37,代码来源:tickets.php

示例14: paginate

 /**
  * @inheritdoc
  */
 protected function paginate()
 {
     $this->collection = $this->collection->slice($this->input['start'], (int) $this->input['length'] > 0 ? $this->input['length'] : 10);
 }
开发者ID:Kirylka,项目名称:Scaffold,代码行数:7,代码来源:CollectionEngine.php

示例15: paginateResults

 /**
  * Paginate a set of record results
  * 
  * @param $records the set of records
  * @param $perPage number of records to show per page
  * @param $request the request object
  *
  * @return the LengthAwarePaginator object
  */
 protected function paginateResults($records, $perPage, $request)
 {
     //Get current page form url e.g. &page=6
     $currentPage = LengthAwarePaginator::resolveCurrentPage();
     //Create a new Laravel collection from the array data
     $collection = new Collection($records);
     //Slice the collection to get the items to display in current page
     $currentPageSearchResults = $collection->slice(($currentPage - 1) * $perPage, $perPage)->all();
     //Create the paginator
     return new LengthAwarePaginator($currentPageSearchResults, count($collection), $perPage, $currentPage, ['path' => $request->url(), 'query' => $request->query()]);
 }
开发者ID:albertopereira,项目名称:iopac,代码行数:20,代码来源:SearchController.php


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