Skip to content

Configuration ​

Add Comments settings to the array returned by config/app.php, or write them through Cake\Core\Configure. The example file at config/app.example.php is a starting point; the plugin does not load it automatically.

Public controller and access ​

SettingDefaultEffect
controllerModelsEmptyAllowed URL aliases mapped to table class names.
allowAnonymousfalsePermit comment creation without a user ID.
userIdFieldidField read from an array-like identity, auth component, or session.
sessionKeyAuth.UserSession path used only without a loaded auth component, before the user ID field.
adminAccessUnsetClosure receiving the request; literal true grants admin and elevated delete access.

Component ​

Per-component configuration overrides the global Comments settings:

php
$this->loadComponent('Comments.Comment', [
    'actions' => ['view'],
    'viewVariable' => 'post',
    'allowAnonymous' => false,
]);
SettingDefaultEffect
actionsUnsetProcess every action when unset; otherwise limit to the named actions.
onbeforeRenderProcess submitted comment data during this callback; startup is also supported.
viewVariableDerived entity nameView variable holding the entity being commented on.
useEntitytrueTake the target ID from the view entity rather than submitted id.
userIdUnsetExplicit server-supplied user ID, before identity and session lookup.
userModelClassUsersUser model name passed when attaching the behavior.

Behavior ​

SettingDefaultEffect
commentClassComments.CommentsComments table class used for the association.
modelParent table aliasExact stored identifier for reads, component/public-controller writes and replies. null resolves to the table alias.
modelClassParent table aliasBack-association to the parent table on the Comments table.
userModelAliasUsersUser association to add if absent.
userModelClassUsersClass for a newly added user association.
userModelUnsetArray of association options for a newly added user association.
countCommentsfalseAttach CounterCache to the Comments table. Requires a parent counter column.
fieldCountercomments_countParent column used with countComments. The migration does not create it.
hiddenFieldUnsetOptional visibility condition in the comments finder. Does not affect other queries.

Set model on each behavior when tables need different identifiers. A global Comments.model supplies the same default to behavior initialization and the public controller when no behavior is attached. Use that global value only for a single comment target. For multiple tables, configure distinct identifiers on each behavior; sharing one identifier also shares comments with the same record ID and dependent deletion scope. A behavior-specific value takes precedence. Attach or configure the behavior before processing comments; changing its setting after initialization does not rebuild association conditions.

The supplied Comments table already has a Users association and its save rule uses that association. Setting a different userModelClass alone does not replace it. Customize the Comments table and its associations if your application uses a different user model.

Historical options such as approval, threaded, titleField, spamField, nameField, and emailField do not implement the behavior suggested by their names. In particular, emailField => false does not enforce signed-in commenting, and userModelClass => false does not enable a guest-only mode. Use allowAnonymous for guest access and implement visibility rules explicitly.