假设我的页面有分页:
本地主机/ FR /用户/索引/页:1
根据我在控制器中定义paginate var的方式,我看到了第1页的正确结果。但是当我点击下一个按钮时,网址会更改为页面:2但结果不会更改并且与页面相同:1,页面相同:3,页面:4等等...
如果我首先对列进行排序,让我们说用户名,那么我可以使用上一个/下一个链接而没有任何问题,每个页面上的数据都会发生变化。
我能想到的唯一可能导致我问题的是我在我的网址中使用语言参数但我不知道如何解决这个问题......
我目前正在使用Cake 1.2.5。我也尝试使用1.3测试版,结果相同。
好的,这是我的用户控制器代码:
var $paginate = array('limit'=>'5');
function index() {
$this->User->recursive = 0;
$this->set('users', $this->paginate());
}
我正在使用teknoid教程进行语言切换:
URL-based language switching...
通过app_helper.php添加语言参数
function url($url = null, $full = false) {
if(!isset($url['language']) && isset($this->params['language'])) {
$url['language'] = $this->params['language'];
}
return parent::url($url, $full);
}
使用app_controller.php中的方法完成语言切换:
function _setLanguage() {
if ($this->Cookie->read('lang') && !$this->Session->check('Config.language')) {
$this->Session->write('Config.language', $this->Cookie->read('lang'));
}
else if (isset($this->params['language']) && ($this->params['language']
!= $this->Session->read('Config.language'))) {
$this->Session->write('Config.language', $this->params['language']);
$this->Cookie->write('lang', $this->params['language'], null, '20 days');
}
}
解决方案:
在设置yahoo boss网站并注意到分页工作正常后,我仔细查看了我的代码,发现问题出在我的routes.php中。
我有这个:
Router::connect('/news', array('controller'=>'news', 'action'=>'index'));
Router::connect('/:language/news', array('controller'=>'news', 'action'=>'index'), array('language'=>'[a-z]{2}'));
我像这样修改了所有参数:
Router::connect('/news/*', etc...
Router::connect('/:language/news/*', etc...
答案 0 :(得分:0)
向我们展示控制器代码,视图代码和一些示例网址。我过去也遇到过类似的问题,但如果你不给我们更多的信息,没有人可以提供帮助。
答案 1 :(得分:0)
Even i faced the similar problem
**Solution**
I closely checked all my code and after trial and errors i was able to find the solution
First the cause: I was doing a order by
$this->paginate = array(
'limit' => 20,
'order' => array('Test.aws_id' => 'asc'),
'conditions' => $condition_options
);
The above code was returning first page result across all pages.
After a while i closely checked everything and the result set.
The resultset was returning me **capital AWS_ID** and i was doing my ordering on aws_id after changing it to caps my code was working
Hope this helps someone