0

私は Cakephp2.0 を使用していて、コメント プラグインを統合したいのですが、何も得られませんでした。ちゃんと。

必要に応じて統合および変更できる簡単なコメント プラグインがあれば教えてください。

ありがとう、

4

1 に答える 1

1

コメントの設定方法は次のとおりです。

コメント テーブルのフィールド:

  • ID
  • parent_type は、親のモデル名と一致します
  • 親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();
?>

次に、モデルのビュー view で、これを追加します (要素に comment.ctp という名前を付けたと仮定します:

<?php echo $this->element('comment',array('data'=>$modelData,'type'=>'MyModel')) ?> 
于 2012-05-25T02:40:38.687 に答える