简体   繁体   English

如何在CakePHP中保存相关数据?

[英]How do I save related data in 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'. 因此,我创建了一个名为“ attached_products”的新表。 It has the fields id, website_id and product_id. 它具有字段ID,website_id和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: 因此,我现在有两个问题,第一个是如何保存将在attach_products表中显示如下内容的网站:

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 以上表示将四个ID为3,5,6,10产品附加到一个ID为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! 我是CakePHP的新手,非常感谢您的帮助! :) :)

You have the right idea about what you're doing. 您对自己的工作有正确的想法。 Read about HABTM relationship in Cake book. 在Cake book中阅读有关HABTM关系的信息。 You should learn more about Cake (from simple to complicated things). 您应该了解有关Cake的更多信息(从简单到复杂的东西)。 That one is pretty hard for a newcomer. 对于一个新手来说,那是相当困难的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM