Cakephp Tagging - 自动保存新标签和标签关系

发布于 2024-07-17 08:15:19 字数 545 浏览 4 评论 0原文

我读了很多有关 CakePHP 中标记的内容,但我找不到一种“干净”的方法来保存帖子和该帖子的标签。 我拥有所有必需的内容:Post 表、模型和控制器、标签表、模型和控制器以及 posts_tags 表。 我在帖子和标签模型中创建了 HABTM 关联。

如果我想保存新帖子,我希望 CakePHP 自动保存与该帖子关联的标签,但我找不到正确的方法。 在大多数教程中,您必须使用“帮助程序”功能(http://www .jamesfairhurst.co.uk/posts/view/full_cakephp_application_part_5 => "_parse_genres") 或类似的东西,但我认为与 CakePHP 的处理就是这样,一旦你设置了它,这一切都是由 Cake 完成的正确的。

所以我的问题是,是否有一种“干净”的蛋糕方式可以做到这一点,或者我是否必须使用辅助函数?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我很难相信您没有找到处理 HABTM 的“正确”方法。 关于它的文章有很多很多。 我相信,如果您正确设置数据数组,Cake 保存您的标签。 快速搜索 The Bakery:

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

将揭示足够的信息。 我猜你正在寻找这个:

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

(请注意,有一个组件可以执行相同的操作,但模型行为是正确的方法)

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文