PHP code example of netcommons / content-comments
1. Go to this page and download the library: Download netcommons/content-comments library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
netcommons / content-comments example snippets
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'
);
}
foreach ($videos as $video) {
echo $video['Video']['title'];
echo $this->ContentComment->count($video);
}
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);
}
}
echo $video['title'];
echo $this->ContentComment->index($video);