[www.it123.org看例子](http://www.it123.org)
入库操作:略
删除操作:略
读取处理:
(读取操作采用递归,填充本评论的父引用回复)
public function getCommentList($id,$module_id){
$commentDB = M('comment');
$where['comment_item_id'] = $id;//文章id
$where['comment_module_id'] = $module_id;//模块id
$commentList= $commentDB->where($where)->order('comment_time desc')->limit(10)->select();
foreach ($commentList as $k =>$v){
//把父级引用求出来存储在本字段
$commentList[$k]['levy']= $this->getParents($commentList,$commentList[$k]['comment_id']);
}
}
public function getParents($list, $comment_id) {
$tree = array();
foreach ($list as $item) {
if ($item['comment_id'] == $comment_id) {
if ($item['comment_pid'] > 0)
$tree = array_merge($tree, self::getParents($list, $item['comment_pid']));
$tree[] = $item;
break;
}
}
return $tree;
}