An extension to CakePHP's core TreeBehavior that provides counterCache functionality for all children and/or direct children of each node in the tree. Packaged as a plugin with a fixture and unit tests with 100% code coverage.
-
Install the plugin from my github account in your APP/plugins directory.
-
Add
child_count
and/ordirect_child_count
integer fields to your database table (you can configure the field names in the settings when you attach the behavior to the model). -
Attach the TreeCounterCache Behavior to your model:
Useful if you ever need to know whether a node has child nodes, e.g. for adding a CSS class to alter the style of that node to indicate to the user there is something beneath it. Caching the count saves extra db queries. To be honest, it's not that great really is it? Still, might be useful to someone.
- Add counterScope functionality