问题描述
在我的路线文件中,我为控制器方法定义了一条路线
in my routes file i define a route for my controller method
$routes->connect('/category/:cat', ['controller' => 'Categories', 'action' => 'category']);
我的控制器方法是这个
public function category(){
$this->paginate = [
'limit' => 2
];
$this->viewBuilder()->layout('newLayout');
$cat = $this->request->params['cat'];
$id = $this->Categories->findBySlug($cat)->select(['id'])->hydrate(false)->toArray();
$cid = $id[0]['id'];
$category = $this->ProductCategories
->find("all")
->select(['id', 'category_id'])
->where(["category_id" => $cid])
->contain(['Products' => function($q){
return $q->select(['id', 'sku', 'product', 'description', 'slug', 'price', 'off', 'stock', 'product_category_id'])
->where(['status' => 1])
->contain(['ProductImages' => function($q){
return $q->select(['product_id','url']);
}]);
}])->hydrate(false);
$categories = $this->paginate($category);
$this->set(compact('categories'));
$this->set('_serialize', ['categories']);
}
我的网址看起来像这样:
And my url look like this:
http://localhost/mizzoli.com/category/Designer-Saree
现在,当我单击蛋糕的分页网址时,将其更改为此
Now when i click on cake pagination url change to this
http://localhost/mizzoli.com/categories/category?page=2
但是我想要的实际网址是这样
But actual url i want is like this
http://localhost/mizzoli.com/category/Designer-Saree?page=2
而且我还需要通过分页URL传递一些额外的参数,例如颜色,场合等.请帮助我获得此信息.我没有找到任何解决方案.
And also i need to pass some extra parameter with pagination url like color, occasion etc. Please help me to get this. I did not find any solution.
推荐答案
我遇到了类似的问题,并通过在路由定义的第三个参数中传递了所需的参数来解决了该问题.像这样:
I had a similar issue and resolved it by passing the param I needed inside the third parameter of the route definition. Like this:
$ routes-> connect('/category/:cat',['controller'=>'Categories','action'=>'category'],['pass'=>['cat']]);
我有来自Freenode上#cakephp IRC频道的@littleylv,感谢您的解决方案.
I have @littleylv from the #cakephp IRC channel on Freenode to thank for this solution.
您可以在此处阅读有关通过路由将参数传递给操作的更多信息: https://book.cakephp.org/3.0/en/development/routing.html#passing-parameters-to-action
You can read more about passing parameters to actions via routes here: https://book.cakephp.org/3.0/en/development/routing.html#passing-parameters-to-action
这篇关于CakePHP 3分页中的自定义路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!