Commentable Behavior
The following should get you up and running with Commentable Behavior. Note that I've only tested it with a "Post" model, but it should work fine otherwise.
Follow the instructions at the following repo and you'll be up and running in no time :)
http://github.com/josegonzalez/cakephp-commentable-behavior
To use the behavior, include it in your model. Please note that if it is not using the standard "Post" model, then you'll have to configure the options array. Take a look at the behavior above for the types of options it will take. Model Class:
1 2 3 4 5 6 | |
You don't need to create a model for 'Comment', unless you plan on doing something special. By default, CakePHP will build a model for tables that don't explicitly have them created. If you name your Comment table something other than comments, however, or would like to do some extra validation/have cool model methods, go right ahead and create a model called comment.php. Otherwise, keep reading.
You'll also need a SQL table to store all your comments. The following will work with the defaults: SQL:
1 2 3 4 5 6 7 8 9 10 11 | |
You'll need a controller action such as the following: Controller Class:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | |
And this view will work wonders when posting to the preceding action View file:
1 2 3 4 5 6 7 8 9 10 11 12 | |
I'm 95% sure that's all that I needed to get everything up and running. If there are any bugs in my code anywhere, drop me a line. I'm also interested in hearing about potential enhancements to the behavior, as it is very basic and doesn't include stuff I'd like such as field validation or associating the comment with a logged in user. Have fun!
Discussion