CakePHP find('threaded') 分页

发布于 2024-08-16 02:33:19 字数 182 浏览 8 评论 0原文

我对 cakePHP 有点陌生,现在我必须进行分页。

评论表有一个parent_id,并且线程查询工作正常,所以现在我想对结果进行分页。

我的问题是有限的 sql 查询会影响所有检索到的评论,我只想限制父级评论,因为相反,它会将回复排除在查询之外。

希望我能说清楚,你能帮助我。

谢谢。

I'm kind of new to cakePHP and get to the moment where i have to do pagination.

The comments table has a parent_id and the threaded query is working correctly so now, I want to paginate the results.

My problem is the limited sql query affects all the retrieved comments and I only want to limit the parent ones because the other way, it leaves replies out of the query.

Hope I'd be clear and you can help me.

Thanks.

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

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

发布评论

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

评论(2

不气馁 2024-08-23 02:33:19

使用:

    var $hasMany = array(
            'ChildComment' => array(
                    'className' => 'ProfileComment',
                    'foreignKey' => 'parent_id',
                    'conditions' => '',
                    'dependent' => true,
                    'fields' => '',
                    'order' => 'created ASC'
            )
    );

        var $belongsTo = array(
            'ParentComment' => array(
                    'className' => 'ProfileComment',
                    'foreignKey' => 'parent_id',
                    'conditions' => '',
                    'fields' => '',
                    'order' => ''
            ));

然后在查找中:

$comments = $this->User->ProfileComment->find('all', array(
                'limit' => $this->incNumber,
                'offset' => $page*$this->incNumber,
                'conditions' => array('ProfileComment.parent_id' => null, 'ProfileComment.user_id' => $id),
                'order' => 'ProfileComment.created DESC'
            ));

您必须根据您的目的自定义代码,但关键点是关系,并且查找条件具有parent_id = null。这样限制只影响父母

Use:

    var $hasMany = array(
            'ChildComment' => array(
                    'className' => 'ProfileComment',
                    'foreignKey' => 'parent_id',
                    'conditions' => '',
                    'dependent' => true,
                    'fields' => '',
                    'order' => 'created ASC'
            )
    );

        var $belongsTo = array(
            'ParentComment' => array(
                    'className' => 'ProfileComment',
                    'foreignKey' => 'parent_id',
                    'conditions' => '',
                    'fields' => '',
                    'order' => ''
            ));

and then in the find:

$comments = $this->User->ProfileComment->find('all', array(
                'limit' => $this->incNumber,
                'offset' => $page*$this->incNumber,
                'conditions' => array('ProfileComment.parent_id' => null, 'ProfileComment.user_id' => $id),
                'order' => 'ProfileComment.created DESC'
            ));

You have to customize the code for your purpose, but the keypoint is the relations and that the find condition has parent_id = null. This way the limit only affects the parents

李不 2024-08-23 02:33:19

您可能需要仅对父级(主题?)进行查询,然后对下面的每棵树进行另一个查询。

You probably need to do the query for just the parents (topics?) then another query for each tree below that.

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