To implement this feature I had created a a column replyTo
which relates to the comment_id
in the same table. The original comments have this as 0
. The problem I face is what could be the best way to show them.
为了实现这个功能,我创建了一个列replyTo,它与同一个表中的comment_id相关。最初的评论将其视为0.我面临的问题可能是展示它们的最佳方式。
In my model, I have created a function nested_comments()
to get them and in my view I was doing like, this.
在我的模型中,我创建了一个函数nested_comments()来获取它们,在我看来我就是这样做的。
<? foreach( $comments as $comment ): ?>
....
<? foreach( $comment->nested_comments() as $comm): ?>
But that is only fine if I have one level of nested comments. Actually, I wish if there was a way to do this in the view. I don't wish to create another view file and controller for this purpose alone.
但是,如果我有一个级别的嵌套注释,那就没问题了。实际上,我希望在视图中有一种方法可以做到这一点。我不希望仅为此目的创建另一个视图文件和控制器。
2 个解决方案
#1
1
You can use function, Like below:
你可以使用函数,如下所示:
function getComments($comments){
if(!is_array($comments)){
return;
}
foreach($comments as $key => $value){
// do what you want with comments
getComments($nestedComments);
}
}
it's not ready to use function, but you can work in the same way.
它还没有准备好使用功能,但你可以以同样的方式工作。
#2
0
You can achieve it with mptt modules, there are a few around:
你可以使用mptt模块实现它,有几个:
https://github.com/spadefoot/kohana-orm-leap
https://github.com/spadefoot/kohana-orm-leap
https://github.com/rafi/orm-mptt
https://github.com/rafi/orm-mptt
https://github.com/evopix/orm-mptt
https://github.com/evopix/orm-mptt
I've been using third one but now its old and I suggest you to take a look at leap, it looks very promising. And also take a look at http://kohana-modules.com/search?query=mptt
我一直在使用第三个,但现在它已经老了,我建议你看看飞跃,它看起来很有希望。另请参阅http://kohana-modules.com/search?query=mptt
#1
1
You can use function, Like below:
你可以使用函数,如下所示:
function getComments($comments){
if(!is_array($comments)){
return;
}
foreach($comments as $key => $value){
// do what you want with comments
getComments($nestedComments);
}
}
it's not ready to use function, but you can work in the same way.
它还没有准备好使用功能,但你可以以同样的方式工作。
#2
0
You can achieve it with mptt modules, there are a few around:
你可以使用mptt模块实现它,有几个:
https://github.com/spadefoot/kohana-orm-leap
https://github.com/spadefoot/kohana-orm-leap
https://github.com/rafi/orm-mptt
https://github.com/rafi/orm-mptt
https://github.com/evopix/orm-mptt
https://github.com/evopix/orm-mptt
I've been using third one but now its old and I suggest you to take a look at leap, it looks very promising. And also take a look at http://kohana-modules.com/search?query=mptt
我一直在使用第三个,但现在它已经老了,我建议你看看飞跃,它看起来很有希望。另请参阅http://kohana-modules.com/search?query=mptt