English 中文(简体)
lumen - LengthAwarePaginator:resolveCurrentPage()
原标题:lumen - LengthAwarePaginator::resolveCurrentPage() is always 1

我与卢门人一样,也存在这样的问题:这总是1,我去/artikel?page=2:

LengthAwarePaginator::resolveCurrentPage();

完整的法典:

<?php namespace AppHttpControllers;

use AppHttpControllersController;
use IlluminatePaginationLengthAwarePaginator;
use IlluminateSupportCollection;


class ArtikelController extends Controller {

    public function index()
    {
        $dir =  ../resources/views/artikel/ ;

        $files = array_diff(scandir($dir), array( .. ,  . ));

        $artikel = array();

        foreach($files as $k => $v)
        {
            $id = substr($v,0,1);
            $artikel[$id][ id ] = $id; 
            $artikel[$id][ name ] = substr($v,0,strpos($v, .blade.php ));
        }

        //Get current page form url e.g. &page=6
        $currentPage = LengthAwarePaginator::resolveCurrentPage();

#dd($currentPage);

        //Create a new Laravel collection from the array data
        $collection = new Collection($artikel);

        //Define how many items we want to be visible in each page
        $perPage = 2;

        //Slice the collection to get the items to display in current page
        $currentPageResults = $collection->slice($currentPage * $perPage, $perPage)->sortByDesc( id )->all();

        //Create our paginator and pass it to the view
        $paginatedResults = new LengthAwarePaginator($currentPageResults, count($collection), $perPage);

        $paginatedResults->setPath( artikel );

        return view( artikel , [ artikel  => $paginatedResults]);
    }

我找不到错误。 原因何在? (我还更新到<代码>“laravel/lumen-framework”:“5.1.*)

最佳回答

您可使用这一简单方式,以方便您的本页。

$currentPage = (int) app( request )->get( page , $default =  0 );
问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签