cakephp 分页下一个和上一个不显示
我正在使用 cakephp 1.3,我收到了奇怪的分页问题。我已经实现了分页,因为我在多个控制器中都有工作分页代码。但是我的控制器的其余部分没有显示下一个和上一个按钮以及分页数字工作正常 我在我的视图中使用此代码
<?php
if(!empty($zipcodes)){
echo "<div class='pagination'>";
echo @$this->Paginator->prev('« Previous', null, null, array('class' => 'disabled'));
echo @$this->Paginator->numbers();
echo @$this->Paginator->next('Next »', null, null, array('class' => 'disabled'));
echo '<div style="float:right;padding:5px;color:#000">'.$this->Paginator->counter().'</div>';
echo "<div class='clear'></div>";
echo "</div>";
}
?>
,并且在我的控制器中,我使用了分页控制器,因为我正在对自定义查询结果进行分页。我在 app_model.php 中包含了分页代码。 我的控制器代码是
var $paginate = array(
'Zipcode' => array('limit' => 5,
'order' => array('id' => 'desc'),
)
);
我的查询和操作,
$tsql = " SELECT Zipcode.* ".
" FROM zipcodes AS Zipcode ".
" WHERE Zipcode.region_id=0 ";
$conditions = array(
'tsql'=>$tsql,
);
$tmp = $this->paginate('Zipcode',$conditions);
$this->set('zipcodes', $tmp);
任何人都可以指出我做错了什么。?以及为什么分页仅适用于某些控制器。???提前致谢
I am using cakephp 1.3 and i am receiving strange problem with pagination.I have imnplemented pagination for I have working pagination code in more than one controller .But my rest of the controller not showing next and previous button and numbers for pagination is working fine
I am using this code in my view
<?php
if(!empty($zipcodes)){
echo "<div class='pagination'>";
echo @$this->Paginator->prev('« Previous', null, null, array('class' => 'disabled'));
echo @$this->Paginator->numbers();
echo @$this->Paginator->next('Next »', null, null, array('class' => 'disabled'));
echo '<div style="float:right;padding:5px;color:#000">'.$this->Paginator->counter().'</div>';
echo "<div class='clear'></div>";
echo "</div>";
}
?>
And in my controller i have used pagination controller as i am paginating custom query results .I included pagination code in app_model.php.
My ontroller code is
var $paginate = array(
'Zipcode' => array('limit' => 5,
'order' => array('id' => 'desc'),
)
);
my query and operation
$tsql = " SELECT Zipcode.* ".
" FROM zipcodes AS Zipcode ".
" WHERE Zipcode.region_id=0 ";
$conditions = array(
'tsql'=>$tsql,
);
$tmp = $this->paginate('Zipcode',$conditions);
$this->set('zipcodes', $tmp);
can any one point out me what i am doing wrong.??And why pagination is working for only some controller .??? THanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,更改控制器顶部的分页。从中删除邮政编码。它应该是:
其次,我不确定你想用 $tsql 来完成什么,但据我所知,你不能传递 SELECT 语句作为条件。您需要像这样编写 ORM 特定条件:
然后要设置邮政编码,您可以这样做:
或 this
作为旁注,
echo @$this->Paginator->prev
应该是echo $this->Paginator->prev
并应从这些行中删除所有@。这是糟糕的编码实践。我不确定你的忽略是否有原因,但这很糟糕。First, change your paginate in the top of the controller. Remove Zipcode from it. It should just be:
Second, I am not sure what you are trying to accomplish with $tsql, but as far as I know, you cannot pass a SELECT statement as a condition. You need to write ORM specific conditions like this:
Then to set zipcodes you can do this:
or this
As a side note,
echo @$this->Paginator->prev
should beecho $this->Paginator->prev
and all the @ should be removed from those lines. That is poor coding practice. I'm not certain if you have the ignore in there for a reason, but it's bad.