\Comment\Model\BehaviorCommentableBehavior

Allow entities to be commented.

Summary

Methods
Properties
Constants
__construct()
beforeFind()
findComments()
bindComments()
unbindComments()
No public properties found
No constants found
No protected methods found
$_table
$_enabled
$_defaultConfig
N/A
No private methods found
No private properties found
N/A

Properties

$_table

$_table : \Cake\ORM\Table

The table this behavior is attached to.

Type

\Cake\ORM\Table

$_enabled

$_enabled : boolean

Enable/Diable this behavior.

Type

boolean

$_defaultConfig

$_defaultConfig : array

Default configuration.

These are merged with user-provided configuration when the behavior is used.

Type

array

Methods

__construct()

__construct(\Cake\ORM\Table $table, array $config)

Constructor.

Here we associate Comments table with the table this behavior is attached to.

Parameters

\Cake\ORM\Table $table

The table this behavior is attached to.

array $config

The config for this behavior.

beforeFind()

beforeFind(\Cake\Event\Event $event, \Cake\ORM\Query $query, array $options, boolean $primary) : void

Attaches comments to each entity on find operation.

Parameters

\Cake\Event\Event $event

The event that was triggered

\Cake\ORM\Query $query

The query object

array $options

Additional options as an array

boolean $primary

Whether is find is a primary query or not

findComments()

findComments(\Cake\ORM\Query $query, array $options) : \Cake\Datasource\ResultSetDecorator

Get comments for the given entity.

Allows you to get all comments even when this behavior was disabled using unbindComments().

Usage:

// in your controller, gets comments for post which id equals 2
$postComments = $this->Posts->find('comments', ['for' => 2]);

Parameters

\Cake\ORM\Query $query

The query object

array $options

Additional options as an array

Throws

\InvalidArgumentException

When the 'for' key is not passed in $options

Returns

\Cake\Datasource\ResultSetDecorator —

Comments collection

bindComments()

bindComments() : void

Enables this behavior.

Comments will be attached to entities.

unbindComments()

unbindComments() : void

Disables this behavior.

Comments won't be attached to entities.