我的代码需要一些帮助

发布于 2024-09-08 03:46:30 字数 607 浏览 3 评论 0原文

我正在使用 cakephp 1.26 并进行分页。 你能帮我解决以下代码吗? 我无法弄清楚代码中有什么问题。

$this->set('posts', $this->paginate = array('order'=>array('Post.created'=> 'DESC'), 'conditions'=>array('Post.zero'=>'0'), 'limit'='6'
)                                           
                    );

在 .ctp 文件中我有这个:

<table>
<tr><td>
       <?php echo $paginator->numbers(); ?>
<?php
    echo $paginator->prev('Previous', null, null);
    echo $paginator->next(' Next', null, null);
?> 

</td></tr>
</table>

I am using cakephp 1.26 and doing pagination.
could you help me with the following code please?
I can't figure out what's wrong in the code.

$this->set('posts', $this->paginate = array('order'=>array('Post.created'=> 'DESC'), 'conditions'=>array('Post.zero'=>'0'), 'limit'='6'
)                                           
                    );

In the .ctp file I have this:

<table>
<tr><td>
       <?php echo $paginator->numbers(); ?>
<?php
    echo $paginator->prev('Previous', null, null);
    echo $paginator->next(' Next', null, null);
?> 

</td></tr>
</table>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

凌乱心跳 2024-09-15 03:46:30

你的代码很糟糕。您不能在函数调用内进行赋值。要么做:

$this->set('posts', $this->paginate('Post',array(
                  'order' => array('Post.created' => 'DESC'),
                  'conditions' => array('Post.zero' => '0'),
                  'limit' => '6'
                  )));

要么:

$this->paginate = array(
    'order' => array('Post.created' => 'DESC'),
    'conditions' => array('Post.zero' => '0'),
    'limit' => '6');

$this->set('posts', $this->paginate('Post'));
);

Your code is bad. You cannot make the assignment within the function call. Either do:

$this->set('posts', $this->paginate('Post',array(
                  'order' => array('Post.created' => 'DESC'),
                  'conditions' => array('Post.zero' => '0'),
                  'limit' => '6'
                  )));

or:

$this->paginate = array(
    'order' => array('Post.created' => 'DESC'),
    'conditions' => array('Post.zero' => '0'),
    'limit' => '6');

$this->set('posts', $this->paginate('Post'));
);
茶底世界 2024-09-15 03:46:30

你的代码不应该是:

$this->set('posts', $this->paginate = array(
    'order' => array('Post.created' => 'DESC'),
    'conditions' => array('Post.zero' => '0'),
    'limit' => '6')
);

Shouldn't your code be:

$this->set('posts', $this->paginate = array(
    'order' => array('Post.created' => 'DESC'),
    'conditions' => array('Post.zero' => '0'),
    'limit' => '6')
);

?

野鹿林 2024-09-15 03:46:30

你可以尝试让这个过程更加清晰。

$this->paginate['Post'] = array('order'=>array('Post.created'=> 'DESC'), 'conditions'=>array('Post.zero'=>'0'), 'limit'='6'));
$posts = $this->paginate('Post');
$this->set(compact('posts'));

You can try to make the process more clear.

$this->paginate['Post'] = array('order'=>array('Post.created'=> 'DESC'), 'conditions'=>array('Post.zero'=>'0'), 'limit'='6'));
$posts = $this->paginate('Post');
$this->set(compact('posts'));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文