Question

I read a lot about tagging in CakePHP but I can't find a "clean" way to save a Post and the Tags to this post. I have all which is necessary the Post Table, Model and Controller, the Tag table, Model and Controller and the posts_tags table. I created the HABTM Associations in the Post and the Tag Model.

If I want to save a new post, I want that CakePHP automagically saves the tags associated to that post, but I can't find the right way for that. In most of the tutorials you have to use a "helper" Function (http://www.jamesfairhurst.co.uk/posts/view/full_cakephp_application_part_5 => "_parse_genres") or something like that, but I thought the deal with CakePHP is it, that this is all done by Cake once you set it up right.

So my question, is there a "clean"-Cake-way to do it, or do I have to use a helper function?

Was it helpful?

Solution

I find it very hard to believe that you didn't find a "proper" way to handle HABTM. There are many, many articles about it. I believe that Cake will save your tags if you set your data array properly. A quick search on The Bakery:

http://bakery.cakephp.org/articles/search/3/HABTM

Will reveal enough. My guess is that you're looking for this:

http://bakery.cakephp.org/articles/view/simple-tagging-behavior

(Note that there is a component which does the same thing, but model behaviour is the right way to go)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top