CakePHP 2.x自定义路由分页 [英] CakePHP 2.x Custom Route Pagination
问题描述
我有一个以下自定义路由(工作正常):
Router :: connect ,array('controller'=>'dealers','action'=>'index'),array('city'=>'[az] +'));
使用此路线,我试图获得分页的页面2,3 ...:
Router :: connect('/:city /:id',array('controller'=>'dealers','action' >'index'),
array(
'pass'=> array('city','id'),
'city'=>'[az] ,
'id'=>'[0-9] +'
)
);
第一个问题现在是,如果我输入 .com / washington / 2 它不会将ID传递给Pagination,我仍然获得第1页。
第二个问题是我没有得到分页助手写上面的链接。如果我在我的观点尝试这个:
$ this-> Paginator-& url'=> array(
$ city [0] ['City'] ['url'],
$ this-> params ['id']
)
)
);
它仍然给我:
em> http://domain.com/dealers/index/washington/page:2
如果这不是一个好主意,我必须提前道歉,但
更新1: / p>
我现在在 domain.com/washington/page/2 尝试以下操作,但它只是路由到分页第1页:
Router :: connect('/:city /:slug /:id',
array('controller'=>
array(
'pass'=> array('city','slug','id'),
' city'=>'[az] +',
'slug'=>'[az] +',
'id'=>'[0-9] +'
)
);
在操作中我执行此操作:
public function index($ slug = null,$ id = null){some code}
在视图中我添加了:
$ this-> Paginator-& ('url'=> $ this-> passedArgs));
仍然没有运气,如果有人能帮助你,我会非常高兴!
我终于有了这个url domain.com/washington/page/2 beforeFilter):
if(isset($ this-> request-> params ['page'])){
$ this-> request-> params ['named'] ['page'] = $ this-> request-> params ['page'];
}
并添加此路线:
Router :: connect('/:city / page /:page',
array('controller'=>'dealers','action' >'index'),
array(
'pass'=> array('city','page'),
'city'=>'[az] ,
'page'=>'[0-9] +'
)
);
但是我真的不明白这里发生了什么,如果这是一个很好的方式。如果有人可以简要解释,我有兴趣知道。
I have a the following custom route (which works fine):
Router::connect('/:city', array('controller' => 'dealers', 'action' => 'index'), array('city' => '[a-z]+'));
With this route, I am trying to get paginated pages 2, 3, …:
Router::connect('/:city/:id', array('controller' => 'dealers', 'action' => 'index'),
array(
'pass' => array('city', 'id'),
'city' => '[a-z]+',
'id' => '[0-9]+'
)
);
The first problem now is, that if I enter domain.com/washington/2 it doesn't pass the id to Pagination and I still get page 1.
The second problem is that I do not get the Pagination Helper to write the above link. If I try this in my view:
$this->Paginator->options(array
('url'=> array(
$city[0]['City']['url'],
$this->params['id']
)
)
);
It still gives me:
http://domain.com/dealers/index/washington/page:2
I apologize in advance if this is a no brainer, but I am new to this and couldn't figure it out with the available questions/answers here, or the docs.
UPDATE 1:
I now tried the following for domain.com/washington/page/2 , but it just routes to pagination page 1:
Router::connect('/:city/:slug/:id',
array('controller' => 'dealers', 'action' => 'index'),
array(
'pass' => array('city', 'slug', 'id'),
'city' => '[a-z]+',
'slug' => '[a-z]+',
'id' => '[0-9]+'
)
);
In the action I am doing this:
public function index($slug = null, $id = null) {some code}
In the view I added:
$this->Paginator->options(array('url' => $this->passedArgs));
Still no luck, I'd be very very glad if someone could help out!
I finally got the url domain.com/washington/page/2 to work by adding this to AppController (beforeFilter):
if (isset($this->request->params['page'])) {
$this->request->params['named']['page'] = $this->request->params['page'];
}
And by adding this route:
Router::connect('/:city/page/:page',
array('controller' => 'dealers', 'action' => 'index'),
array(
'pass' => array('city', 'page'),
'city' => '[a-z]+',
'page' => '[0-9]+'
)
);
However I do not really understand what happens here, and if this is a good way of doing it. If someone could briefly explain, I'd be interested to know.
这篇关于CakePHP 2.x自定义路由分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!