PHP code example of kareylo / cakephp-comments

1. Go to this page and download the library: Download kareylo/cakephp-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/ */

    

kareylo / cakephp-comments example snippets


Plugin::load('Kareylo/Comments', [
    'routes' => true
]);

$this->addBehavior('Kareylo/Comments.Commentable');

public function initialize()
{
    $this->loadHelper('Kareylo/Comments.Comment');
}

$data = $this->Model->find()->where(['Model.id' => $id])->find('comments')->first();
$this->set(compact('data'));

$this->Comment->display($data);

// in your view
    <div class="row">
        <h4>Commentaires</h4>
        <ul class="comment-list">
             foreach ($model->comments as $comment):
                echo $this->Comment->comment($comment);
            endforeach; 

/** src/Template/Element/Comments/comment.ctp
* $connected is used to check is user is connected
*/
<div class="comment-avatar">
    <i class="fa fa-user"></i>
</div>
<div class="comment-container">
    <div class="comment-author">
        <?= $comment->user->username; 

 //src/Template/Element/Flash/Comments/comment.ctp
 
 if (!isset($params['escape']) || $params['escape'] !== false) {
     $message = h($message);
 }