2017 © Pedro PelĂĄez
 

cakephp-plugin cakephp-comments

A fully customizable Comments plugin for CakePHP 3.

image

kareylo/cakephp-comments

A fully customizable Comments plugin for CakePHP 3.

  • Thursday, August 24, 2017
  • by Kareylo
  • Repository
  • 3 Watchers
  • 4 Stars
  • 104 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 3 Forks
  • 3 Open issues
  • 6 Versions
  • 11 % Grown

The README.md

Fully customizable Comments Plugin for CakePHP 3

Build Status Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

The Comments plugin will allow you comment every model with the possibility to change the template in your APP., (*2)

This plugin works with a behavior and a helper you need to load to fully works., (*3)

Requirements

  • CakePHP 3.4+
  • PHP 5.6+
  • AuthComponent

Installation

composer require kareylo/cakephp-comments

load the plugin in your config/bootstrap.php :, (*4)

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

Add in the ModelTable you wanna be commentable the following behavior :, (*5)

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

The behavior can take these options : * modelClass : Class name of the ModelTable. * Default : null * commentClass : Name of your CommentsTable if you have one. * Default : Kareylo/Comments.Comments * foreignKey : Name of your custom foreignKey. * Default : ref_id * countComments : Put true if you wanna your model count its Comments * Default : false * fieldCounter : Name of your counter field * Default : comments_count, (*6)

Add the following helper in your src/View/AppView.php, (*7)

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

The helper can take these options : * type The HTML tag that will surround your comments * Default ul * Accept ul, ol, div * typeClass the CSS class your type need to have * Default null * subTypeClass The CSS class your subType need to have * Default null * loadJS Put true if you wanna default JS to be loaded * Default false, (*8)

Usage

Get all your comments with the comments finder, (*9)

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

To display your comments, (*10)

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

You can also chose to not use display($data) and use a loop to have the full control of your template, (*11)

// in your view
    <div class="row">
        <h4>Commentaires</h4>
        <ul class="comment-list">
            <?php foreach ($model->comments as $comment):
                echo $this->Comment->comment($comment);
            endforeach; ?>
        </ul>
        <!-- loadJS and display the comment Form if user is connected -->
        <?= $this->Comment->loadFormAndJS($model); ?>
    </div>

Templates

To create templates for the comment block (1 comment) and the form block, create the views you want if src/Template/Element/Comments. Example :, (*12)

/** src/Template/Element/Comments/comment.ctp
* $connected is used to check is user is connected
*/


= $comment->user->username; ?> on = $comment->created->format("l, d M y"); ?> at = $comment->created->format("H:i:s"); ?>
= h($comment->id); ?>
children): ?>
    children as $child) { echo $this->Comment->comment($child); } ?>
// src/Template/Element/Comments/form.ctp = $this->Form->create($comment, ['id' => 'commentForm', 'url' => ['controller' => 'Comments', 'action' => 'add', 'plugin' => 'Comments']]); ?> <?= $this->Flash->render('comment'); ?> <?= $this->Form->control('content', ['label' => __('Commentaire'), 'type' => 'textarea']); ?> <?= $this->Form->hidden('ref'); ?> <?= $this->Form->hidden('ref_id'); ?> <?= $this->Form->unlockField('parent_id'); ?> <?= $this->Form->hidden('parent_id', ['default' => null]); ?> <?= $this->Form->button(__('Commenter')) ?> = $this->Form->end() ?>

To create the template for your flash, just add a element in src/Template/Element/Flash/Comments and name it comment.ctp ```php //src/Template/Element/Flash/Comments/comment.ctp , (*13)

= $message ?>

``` - $params['class'] can have the values success and error, (*14)

Support

For bugs and feature requests, please use the issues section of this repository., (*15)

Contribute

Follow this guide to contribute, (*16)

License

Licensed under the MIT License. Redistributions of the source code included in this repository must retain the copyright notice found in each file., (*17)

TODO

  • [X] Test cases
    • [ ] Improved Test Cases (like test Helper)
  • [ ] More features
  • [ ] Translation

The Versions

24/08 2017

dev-master

9999999-dev https://github.com/Kareylo/CakePHP-Comments

A fully customizable Comments plugin for CakePHP 3.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Corentin Nazé

template cakephp helper behavior comments polymorphic

24/08 2017

dev-add-stickler-config

dev-add-stickler-config https://github.com/Kareylo/CakePHP-Comments

A fully customizable Comments plugin for CakePHP 3.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Corentin Nazé

template cakephp helper behavior comments polymorphic

02/05 2017

v0.0.4

0.0.4.0 https://github.com/Kareylo/CakePHP-Comments

A fully customizable Comments plugin for CakePHP 3.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Corentin Nazé

template cakephp helper behavior comments polymorphic

10/04 2017

v0.0.3

0.0.3.0 https://github.com/Kareylo/CakePHP-Comments

A fully customizable Comments plugin for CakePHP 3.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Corentin Nazé

template cakephp helper behavior comments polymorphic

24/03 2017

v0.0.2

0.0.2.0 https://github.com/Kareylo/CakePHP-Comments

A fully customizable Comments plugin for CakePHP 3.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Corentin Nazé

template cakephp helper behavior comments polymorphic

24/03 2017

v0.0.1

0.0.1.0 https://github.com/Kareylo/CakePHP-Comments

A fully customizable Comments plugin for CakePHP 3.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Corentin Nazé

template cakephp helper behavior comments polymorphic