我要将CakePHP v2升级到v3&想要匹配网址。所以我需要从
更改分页网址http://www.website.net/articles
http://www.website.net/articles?page=2
到
http://www.website.net/articles
http://www.website.net/articles/page/2
但似乎没有用。
这是我的路由器
$routes->connect('/articles', ['controller' => 'Articles', 'action' => 'index']);
$routes->connect('/articles/page/:page', ['controller' => 'Articles', 'action' => 'index'], ['pass' => ['page']]);
这是我的控制器
public $paginate = [
'limit' => 2,
];
public function initialize()
{
parent::initialize();
$this->loadComponent('Paginator');
}
public function index($page = 1)
{
$this->set('articles', $this->Articles->find('all'));
$this->set('articles', $this->paginate());
}
在CakePHP v2中我在控制器中有以下这一行,它假设从路由器传输页码但在v3中似乎不起作用
$this->request->params['named']['page'] = $page;
感谢这方面的帮助。