如何在CakePHP中保存相关数据?
我有一个“网站”和“产品”表。产品可以附加到不同的网站。所以我创建了一个名为“attached_products”的新表。它具有字段 id、website_id 和 Product_id。
所以我现在有两个问题,第一个问题是如何保存一个网站,该网站将在attached_products表中显示类似这样的内容:
id | website_id | product_id
1 | 4 | 3
2 | 4 | 5
3 | 4 | 6
4 | 4 | 10
上面的意思是id为3,5,6,10
的四个产品附加到 ID 为 4
的网站
我的第二个问题是,如何修改记录,例如我想删除附加到网站的两个产品?
我是 CakePHP 的新手,非常感谢您的帮助! :)
I have a 'websites' and 'products' table. The a product can be attached to different websites. So I created a new table called 'attached_products'. It has the fields id, website_id and product_id.
So I have two questions for now, the first one is how do I save a website that will appear something like this in the attached_products table:
id | website_id | product_id
1 | 4 | 3
2 | 4 | 5
3 | 4 | 6
4 | 4 | 10
the above means four products with ids 3,5,6,10
were attached to a website with an id of 4
my second question is, how do I modify the record for example I want to remove the two products attached to a website?
I'm new to CakePHP, many thanks for any help! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您对自己正在做的事情有正确的想法。在 Cake 书中了解 HABTM 关系。你应该更多地了解Cake(从简单到复杂的事情)。这对于一个新人来说是相当困难的。
You have the right idea about what you're doing. Read about HABTM relationship in Cake book. You should learn more about Cake (from simple to complicated things). That one is pretty hard for a newcomer.