netcommons/content-comments

NetCommons 插件的内容评论

安装数: 25,177

依赖项: 5

建议者: 0

安全性: 0

星标: 0

关注者: 13

分支: 1

开放问题: 0

类型:cakephp-plugin

3.3.7.0 2023-10-09 08:41 UTC

README

Tests Status Coverage Status Stable Version

phpdoc

概述

提供在内容列表中显示评论数和在内容详情中发表评论的功能。
请定义使用的插件以确定是否使用评论(use_comment)和是否需要评论审核(use_comment_approval)。

在内容列表中显示评论数

使用 ContentCommentBehavior 和 ContentCommentHelper。
在关联评论的模型中定义 ContentCommentBehavior,
在内容列表控制器中定义 ContentCommentHelper。

示例代码
控制器
class VideosController extends VideosAppController {

	public $uses = array(
		'Videos.Video',
		'Videos.VideoSetting'
	);

	public $helpers = array(
		'ContentComments.ContentComment' => array(
			'viewVarsKey' => array(
				'contentKey' => 'video.Video.key',
				'contentTitleForMail' => 'video.Video.title',
				'useComment' => 'videoSetting.use_comment',
				'useCommentApproval' => 'videoSetting.use_comment_approval'
			)
		)
	);

	public function index() {
		$query = array(
			'conditions' => array(
				'VideoSetting.block_key' => Current::read('Block.key')
			)
		);
		$viewVars['videoSetting'] = $this->VideoSetting->find('first', $query);
		$viewVars['videos'] = $this->Video->find('all');

		$this->set($viewVars);
	}
}
模型
class Video extends VideoAppModel {
	public $actsAs = array(
		'ContentComments.ContentComment'
	);
}
视图(ctp 模板)
<?php
	foreach ($videos as $video) {
		echo $video['Video']['title'];
		echo $this->ContentComment->count($video);
	}
?>

在内容详情中发表评论

使用 ContentCommentsComponent 和 ContentCommentHelper。
在内容详情控制器中定义 ContentCommentsComponent。

示例代码
控制器
class VideosController extends VideosAppController {

	public $uses = array(
		'Videos.Video',
		'Videos.VideoSetting'
	);

	public $components = array(
		'ContentComments.ContentComments' => array(
			'viewVarsKey' => array(
				'contentKey' => 'video.Video.key',
				'contentTitleForMail' => 'video.Video.title',
				'useComment' => 'videoSetting.use_comment'
				'useCommentApproval' => 'videoSetting.use_comment_approval'
			),
			'allow' => array('view')
		)
	)

	public function view($videoKey) {
		$query = array(
			'conditions' => array(
				'VideoSetting.block_key' => Current::read('Block.key')
			)
		);
		$viewVars['videoSetting'] = $this->VideoSetting->find('first', $query);

		$query = array(
			'conditions' => array(
				'Video.key' => $videoKey,
				'Video.language_id' => Current::read('Language.id')
			)
		);
		$viewVars['video'] = $this->Video->find('first', $query);

		$this->set($viewVars);
	}
}
视图(ctp 模板)
<?php
	echo $video['title'];
	echo $this->ContentComment->index($video);
?>