Skip to content

Configuration ​

The example configuration can be merged into the array returned by your application configuration file. It does not replace that file.

NamespaceKeyPurpose
RatingstableRuntime ratings table name; default ratings
RatingsuserClassUsers association class; default Users
PolymorphictypeBundled migration's foreign-key type; default integer

Component and behavior settings are supplied when loading them; the Ratings namespace does not globally configure either one or the helper.

Behavior settings ​

OptionDefaultMeaning
modelClassrated table aliasAssociation back to the rated table
rateClassRatings.RatingsRatings table class
foreignKeyforeign_keyAssociation foreign key; persistence uses the standard ratings schema
fieldratingCalculated result field
fieldSummaryrating_sumCached sum field
fieldCounterrating_countCached count field
calculationaverageAverage or sum
saveToFieldtrueStore result; false calculates only, a string selects a field
updatefalsePermit replacement of a previous vote
userFielduser_idOwner field for the self-vote guard; null disables it
modelValidatefalseRated-record validation when patching calculated fields

countRates and modelCallbacks are retained legacy settings. CakePHP 5 does not implement the old association counterCache option or the save callbacks option used here. Do not rely on those flags to count votes or disable ORM events. Use the configured cache fields and normal CakePHP event handling.

Component settings ​

actions, modelName, userId, userIdField and allowFallbackClass are component-specific. Defaults are all actions, automatic table detection, identity lookup, id and true respectively. params defaults to null rate and rating, with redirect true. The component passes its remaining configuration to the behavior only when attaching it.

The helper's form defaults are its public defaults array and per-call options. Constructor options are not automatically merged into the form's defaults.

Released under the MIT License.