简体   繁体   中英

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'. 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! :)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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