https://github.com/proloser/cakephp-closurebehavior
An efficient alternative to CakePHP Tree Behavior
https://github.com/proloser/cakephp-closurebehavior
Last synced: about 1 year ago
JSON representation
An efficient alternative to CakePHP Tree Behavior
- Host: GitHub
- URL: https://github.com/proloser/cakephp-closurebehavior
- Owner: ProLoser
- Created: 2012-01-09T06:47:05.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2012-02-05T09:58:49.000Z (over 14 years ago)
- Last Synced: 2025-04-04T07:45:02.872Z (about 1 year ago)
- Language: PHP
- Homepage:
- Size: 94.7 KB
- Stars: 14
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# CakePHP Closure Behavior
An efficient alternative to the CakePHP Tree Behavior
## Background
I was working on a project, where I listed multiple posts on the homepage and wanted to show the categories they fell under as breadcrumbs. Normally the tree behavior works just fine, but if I have 40 posts, I now do 1 query for the list of posts and 40 queries to get a list of all ancestor categories for the post. This didn't seem like a good idea, so I started to look for ways around this. generateTreeList and an iterator function seemed more viable, cutting my query down to 2, but the function itself would prove to be complex and slow.
After searching for feedback on irc.freenode.net/php someone pointed me to an [interesting slideshow](http://www.slideshare.net/billkarwin/sql-antipatterns-strike-back) where I learned about the 'Closure' pattern (page 68). It seems to be a much more efficient alternative to MPTT. So this is my attempt to implement it.
An interesting example implementation: http://codepad.org/pR5r68V0
## Installation
### With Git
```
git submodule add git@github.com:ProLoser/CakePHP-ClosureBehavior.git Plugin/Closure
```
### Without Git
[Download package](https://github.com/ProLoser/CakePHP-ClosureBehavior/downloads) and extract to Plugin/Closure