Cakephp CMS教程PaginatorComponent被弃用,抛出警告

Cakephp CMS Tutorial PaginatorComponent is deprecated, throws warnings

提问人:parantur res 提问时间:10/11/2023 最后编辑:parantur res 更新时间:10/11/2023 访问量:46

问:

cakephp 上的内容管理教程抛出有关分页器的弃用错误。

此代码是警告的来源。

<?php
// src/Controller/ArticlesController.php
namespace App\Controller;

use App\Controller\AppController;

class ArticlesController extends AppController
{
    public function initialize(): void
    {
        parent::initialize();

        $this->loadComponent('Paginator');
        $this->loadComponent('Flash'); // Include the FlashComponent
    }

    public function index()
    {
        $articles = $this->Paginator->paginate($this->Articles->find());
        $this->set(compact('articles'));
    }

它生成警告Deprecated (16384) : PaginatorComponent is deprecated, use a Cake\Datasource\Pagination\NumericPaginator instance directly. /home/..../vendor/cakephp/cakephp/src/Controller/ComponentRegistry.php, line: 133

找到两个更改来源的提示。删除 loadComponent 并更改分页方法。

<?php
// src/Controller/ArticlesController.php
namespace App\Controller;

use App\Controller\AppController;

class ArticlesController extends AppController
{
    public function initialize(): void
    {
        parent::initialize();
        $this->loadComponent('Flash'); // Include the FlashComponent
    }

    public function index()
    {
    // Paginate the ORM table.
    $this->set('articles', $this->paginate($this->Articles));
    }

分页的背景 4.x cakephp doc 分页

蛋糕php 分页

评论

0赞 Salines 10/12/2023
你的问题是?
0赞 parantur res 10/12/2023
不再是问题了;在尝试了不同的方法后,我找到了解决方案,但由于这是官方教程中的错误,并且没有解释解决方案,我想我会发布它。

答: 暂无答案