is there way paginate comments in cakephp tree behavior? should use tree behavior anyway or make own code view comments?
sorry, has been asked before. found article: managing hierarchical data in mysql ...and post solution.
nope, didn't find solution. don't want reinvent wheel, want make in cake way.
i wrote helper recursively print comments:
# view/helpers/comments class commentshelper extends apphelper{ public function printcomments($comments = array(), $params = array()){ if (empty($comments) || !is_array($comments)) return false; echo '<ul id="comments-'.$comments[0]['forum']['id'].'">'; if (is_array($comments)){ foreach($comments $comment): ?> <li id="<?php echo $comment['forum']['id']; ?>"> <div class="inner"> <h4><?php echo $comment['forum']['title']; ?></h4> <div class="meta"> <?php echo $comment['user']['first_name']; ?> </div> <div class="content"> <?php echo $comment['forum']['content']; ?> </div> </div> <?php if (isset ($comment['children'])) if (is_array($comment['children'])){ if (!empty($comment['children'])) $this->printcomments($comment['children']); } echo '</li>'; endforeach; } else{ echo '<li>'.$comment['forum']['title'].'</li>'; } echo '</ul>'; }
here how retrieve data database:
# controllers/forums.php $this->set('tree', $this->forum->find('threaded'););
the problem how paginate comments?
currently i'm using 2 tables, 1 root , 2nd threaded comments. didn't find solution.
you have manually in controller paginate.
the key order mysql query find comment not id firstly parent_id , id (columns example) - work 2 level comments:
$this->paginate = array( 'recursive' => -1, 'conditions' => array( 'comment.blog_id' => 0, ), 'order' => array('parent_id', 'id'), 'limit' => 10 ); $this->set('comments', $this->paginate('comment'));
Comments
Post a Comment