PHPackages                             kareylo/cakephp-comments - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. kareylo/cakephp-comments

AbandonedArchivedCakephp-plugin[Templating &amp; Views](/categories/templating)

kareylo/cakephp-comments
========================

A fully customizable Comments plugin for CakePHP 3.

v0.0.4(9y ago)82.0k↓33.3%3[2 issues](https://github.com/Kareylo/CakePHP-Comments/issues)[1 PRs](https://github.com/Kareylo/CakePHP-Comments/pulls)MITPHPPHP &gt;=5.6.0

Since Mar 24Pushed 7y ago3 watchersCompare

[ Source](https://github.com/Kareylo/CakePHP-Comments)[ Packagist](https://packagist.org/packages/kareylo/cakephp-comments)[ Docs](https://github.com/Kareylo/CakePHP-Comments)[ RSS](/packages/kareylo-cakephp-comments/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (4)Versions (6)Used By (0)

Fully customizable Comments Plugin for CakePHP 3
================================================

[](#fully-customizable-comments-plugin-for-cakephp-3)

[![Build Status](https://camo.githubusercontent.com/13e1b34c76e8b26a374ec752dccb4fb628806321607a04c133ad5f42d9450383/68747470733a2f2f7472617669732d63692e6f72672f4b617265796c6f2f43616b655048502d436f6d6d656e74732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Kareylo/CakePHP-Comments)[![Latest Stable Version](https://camo.githubusercontent.com/723064bfe4f45dddb6bde2e0bf86b5881cfa783b21a5566b3f5fb73ff1f244b4/68747470733a2f2f706f7365722e707567782e6f72672f6b617265796c6f2f63616b657068702d636f6d6d656e74732f762f737461626c65)](https://packagist.org/packages/kareylo/cakephp-comments)[![Total Downloads](https://camo.githubusercontent.com/e323837511e3e6ad6e6f4e1a668c759d9fa1c59d29034edf1e35276a97b6e05e/68747470733a2f2f706f7365722e707567782e6f72672f6b617265796c6f2f63616b657068702d636f6d6d656e74732f646f776e6c6f616473)](https://packagist.org/packages/kareylo/cakephp-comments)[![Latest Unstable Version](https://camo.githubusercontent.com/45d70831d2319c2fab2d201c8b6e6865400aeed8bf1f07c6a1d68ee7f2baca44/68747470733a2f2f706f7365722e707567782e6f72672f6b617265796c6f2f63616b657068702d636f6d6d656e74732f762f756e737461626c65)](https://packagist.org/packages/kareylo/cakephp-comments)[![License](https://camo.githubusercontent.com/be87d6c906af15c30f4dd1bdcaafa29096b248a54f2abef643c6a8e27d142898/68747470733a2f2f706f7365722e707567782e6f72672f6b617265796c6f2f63616b657068702d636f6d6d656e74732f6c6963656e7365)](https://packagist.org/packages/kareylo/cakephp-comments)

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

This plugin works with a behavior and a helper you need to load to fully works.

Requirements
------------

[](#requirements)

- [CakePHP](https://github.com/cakephp/cakephp) 3.4+
- PHP 5.6+
- AuthComponent

Installation
------------

[](#installation)

```
composer require kareylo/cakephp-comments

```

load the plugin in your `config/bootstrap.php` :

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

Add in the ModelTable you wanna be commentable the following behavior :

```
$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`

Add the following helper in your `src/View/AppView.php`

```
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`

Usage
-----

[](#usage)

Get all your comments with the comments finder

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

To display your comments

```
$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

```
// in your view

        Commentaires

```

### Templates

[](#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 :

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

        on  at
