cake2.0的评论插件

时间:2012-05-24 07:23:29

标签: cakephp comments cakephp-2.0

我正在使用cakephp2.0并希望整合评论插件,但我什么都没有。我使用的是commentDc插件,但它不能满足我的要求。因为我正在整合我的用户登录系统xenforo和commentDc插件使用Auth组件所以它不能正常工作。

请告诉我有没有简单的评论插件,我可以根据需要进行整合和修改。

谢谢,

1 个答案:

答案 0 :(得分:1)

以下是我设置评论的方式:

评论表字段:

  • ID
  • parent_type,匹配父
  • 的型号名称
  • PARENT_ID
  • 含量
  • user_id,发件人

在任何你想要评论的模型中,你的协会都是:

public $hasMany = array(
        'Comment' => array(
            'className' => 'Comment', 
            'foreignKey' => 'parent_id', 
            'conditions' => array('Comment.parent_type' => 'question')
        )
    );

这是一个视图元素:

<?php
/*
set variables:
$data : data of the parent
$type : the type of the parent
*/
if(!isset($name)) {
$name = 0;
}
foreach($data['Comment'] as $comment){
    echo '<div class="comment">'.$comment['content'].
        ' - '.$this->Html->link($comment['User']['username'],array('controller'=>'users','action'=>'view',$comment['User']['id']))
        .'</div>';
}
echo $this->Form->create(null, array('url' => '/comments/add','id'=>'qCommentForm'));
echo $this->Form->input('Comment.parent_id', array('type'=>'hidden','value'=>$data[$type]['id']));
echo $this->Form->input('Comment.parent_type', array('type'=>'hidden','value'=>$type));
echo $this->Form->textarea('Comment.content',array('div'=>'false','class'=>'small','label'=>false));
echo $this->Form->submit(__('Leave comment'),array('div'=>'false','class'=>'small'));
echo $this->Form->end();
?>

然后,在模型的视图视图中,添加此项(假设您将元素命名为comment.ctp:

<?php echo $this->element('comment',array('data'=>$modelData,'type'=>'MyModel')) ?>