提问人:parantur res 提问时间:10/11/2023 最后编辑:parantur res 更新时间:10/11/2023 访问量:46
Cakephp CMS教程PaginatorComponent被弃用,抛出警告
Cakephp CMS Tutorial PaginatorComponent is deprecated, throws warnings
问:
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 分页
答: 暂无答案
评论