我怎样才能使用Eloquent 5.3 Pagination with Twig

时间:2016-12-21 10:54:21

标签: php symfony pagination herbert

最近我将我的Eloquent升级到最新版本并且分页停止工作。基本上当我调用链接(),在树枝上打印分页时,我收到以下错误消息

Fatal error: Uncaught Error: Call to a member function make() on null in /Applications/XAMPP/xamppfiles/htdocs/*****/public_html/wp-content/plugins/crm/vendor/illuminate/pagination/LengthAwarePaginator.php:140 
Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/*****/public_html/wp-content/plugins/crm/vendor/illuminate/pagination/LengthAwarePaginator.php(119): Illuminate\Pagination\LengthAwarePaginator->render(NULL) 
#1 /Applications/XAMPP/xamppfiles/htdocs/*****/public_html/wp-content/plugins/crm/app/Providers/CMSServiceProvider.php(115): Illuminate\Pagination\LengthAwarePaginator->links() 
#2 /Applications/XAMPP/xamppfiles/htdocs/*****/public_html/wp-content/twig-cache/18/189d0df44f1fe623fdad2b6fb631c15897dda3614de070c872657111c85f5f1a.php(333): Herbert\Framework\Application->{closure}(Object(Illuminate\Pagination\LengthAwarePaginator)) 
#3 /Applications/XAMPP/xamppfiles/htdocs/*****/public_html/wp-content/plugins/properties-integration/ in /Applications/XAMPP/xamppfiles/htdocs/*****/public_html/wp-content/plugins/crm/vendor/illuminate/pagination/LengthAwarePaginator.php on line 140

然后,如果我在控制器内dd($clients->links()),我收到以下错误消息

Warning: call_user_func() expects parameter 1 to be a valid callback, no array or string given in /Applications/XAMPP/xamppfiles/htdocs/*****/public_html/wp-content/plugins/crm/vendor/illuminate/pagination/AbstractPaginator.php on line 377

但是,如果我dd($clients),我将获得具有所选记录和当前页面的Eloquent对象。

这是类

的链接

https://github.com/illuminate/pagination/blob/5.3/LengthAwarePaginator.php#L140-L143

https://github.com/illuminate/pagination/blob/master/AbstractPaginator.php#L405-L424

更新

我做了一个临时解决方案,基本上我使用了AbstractPaginator的可用功能。如果有人有更好的方法,请随时发布。

$function = new Twig_SimpleFunction("render", function ($object) {
    $html = '';
    $data = array(); // start out array
    $data['pages'] = ceil($object->total() / $object->perPage()); // calc pages
    $data['si'] = ($object->currentPage() * $object->perPage()) - $object->perPage(); // what row to start at
    $data['curr_page'] = $object->currentPage(); // Whats the current page

    $max = 7;

    if ($data['curr_page'] < $max) {
        $sp = 1;
    } elseif ($data['curr_page'] >= ($data['pages'] - floor($max / 2))) {
        $sp = $data['pages'] - $max + 1;
    } elseif ($data['curr_page'] >= $max) {
        $sp = $data['curr_page'] - floor($max / 2);
    }

    if ($data['curr_page'] > $max) {
        $html .= '<li ><a href="' . $object->url(1) . '">First Page</a></li>';
    }

    for ($i = $sp; $i <= ($sp + $max - 1); $i++) {

        if ($i > $data['pages']) {
            continue;
        }

        if ($object->currentPage() == $i) {
            $html .= ' <li class="active">';
        } else {
            $html .= '<li >';
        }
        $html .= ' <a href="' . $object->url($i) . '">' . $i . '</a>
                    </li>';

    }

    if ($data['curr_page'] < ($data['pages'] - floor($max / 2))) {
        $html .= '<li ><a href="' . $object->url($object->lastPage()) . '">Last Page</a></li>';
    }

    return $html;

});

0 个答案:

没有答案