views:

987

answers:

1

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?

+2  A: 

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)

dr Hannibal Lecter
ok thx for the links, I have found those too but I didn't know that this is the clean way to go. But you're right, the behavior one looks quite right
nolandark
Glad I could help! Be sure to search the cakephp google group for HABTM if you get into trouble, there are many discussions on it (and I really do mean *many*).
dr Hannibal Lecter