簡體   English   中英

雄辯的分頁不適用於Slim 3框架

[英]Eloquent pagination not working with Slim 3 framework

我已經基於Alex的Gareet“使用Slim 3進行身份驗證”課程構建了Costom MVC系統。 如果我執行$ users = User :: paginate(10)之類的操作,它可以很好地處理雄辯的分頁。 我完全回到了我的期望。 當我嘗試使用$ users-> links();渲染出paginaton鏈接時,問題就來了。 或$ users-> render(); 我得到了休閑的錯誤:

類型:錯誤消息:在空文件上調用成員函數make()文件:C:\\ Users \\ Andy \\ Google_Drive \\ wamp \\ www \\ proline \\ new_admin \\ vendor \\ illuminate \\ pagination \\ LengthAwarePaginator.php行:90

經過廣泛的Google搜索,我發現不是我唯一遇到此問題的人,但是我找不到提供清晰解決方案的人,除了創建自己的渲染功能外,我真的想避免,所以我繼續為了對雄辯的庫進行逆向工程,而我無法理解,則問題似乎是Illuminate \\ Support \\ ServiceProvider \\ PaginationServiceProvider類,該類具有方法“ boot”和“ register”,這似乎與分頁視圖的設置有關,但是整個班級都沒有被實例化。 為了對此進行測試,我在啟動和注冊方法中都執行了一條die語句,其中包含一個字符串,並且未進行任何更改,我試圖“更新” PaginationServiceProvider類的實例,但出現一個新錯誤,說父類的構造函數“ ServiceProvider”期望\\ Illuminate \\ Contracts \\ Foundation \\ Application的新實例為他的論點。 我不知道哪個班級執行此合同。 然后我以為我需要將Slim作為服務注冊此類,並且我嘗試了使用Slim注冊服務的標准方法

$ container ['esp'] =函數($ container)use($ capsule){返回新的Illuminatee \\ Events \\ EventServiceProvider($ container); };

$ container ['dsp'] =函數($ container)use($ capsule){返回新的Illuminatee \\ Database \\ DatabaseServiceProvider($ container); };

女巫什么也沒做。

我迫切需要一些幫助!

如果您仍在掙扎,答案在這里: https : //codecourse.com/watch/slim-3-pagination

基本上,您必須讓composer require illuminate/pagination ,然后構建一個ViewFactory類,該類實現LengthAwarePaginator使用的make()方法,然后進行全局注冊:

```PHP

\Illuminate\Pagination\LengthAwarePaginator::viewFactoryResolver(function () {
            $paths = [
                config()->get('app.settings.paths.landers'),
                config()->get('app.settings.paths.views')
            ];

            $settings = [
                'cache' => config()->get('app.settings.paths.cache.views'),
                'debug' => config()->get('app.debug') // this also auto reloads views cache if set to true
            ];
            return new \Klever\Views\ViewFactory($paths, $settings);
        });

        \Illuminate\Pagination\LengthAwarePaginator::defaultView('partials/pagination.twig');

        \Illuminate\Pagination\Paginator::currentPathResolver(function () {
            return isset($_SERVER['REQUEST_URI']) ? strtok($_SERVER['REQUEST_URI'], '?') : '/';
        });

        \Illuminate\Pagination\Paginator::currentPageResolver(function () {
            return $_GET['page'] ?? 1;
        });

```

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM