cakephp 分页下一个和上一个不显示

发布于 2025-01-08 16:03:19 字数 1525 浏览 0 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情域 2025-01-15 16:03:19

首先,更改控制器顶部的分页。从中删除邮政编码。它应该是:

var $paginate = array(
   'limit' => 5,
   'order' => array('Zipcode.id' => 'desc'),                                        
);  

其次,我不确定你想用 $tsql 来完成什么,但据我所知,你不能传递 SELECT 语句作为条件。您需要像这样编写 ORM 特定条件:

$this->paginate = array(
  'conditions' => array('Zipcode.region_id' => 0),
);

然后要设置邮政编码,您可以这样做:

$this->set('zipcodes', $this->paginate('Zipcode'));

或 this

$data = $this->paginate('Zipcode');
$this->set(compact('data'));

作为旁注, 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:

var $paginate = array(
   'limit' => 5,
   'order' => array('Zipcode.id' => 'desc'),                                        
);  

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:

$this->paginate = array(
  'conditions' => array('Zipcode.region_id' => 0),
);

Then to set zipcodes you can do this:

$this->set('zipcodes', $this->paginate('Zipcode'));

or this

$data = $this->paginate('Zipcode');
$this->set(compact('data'));

As a side note, echo @$this->Paginator->prev should be echo $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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文