views:

13

answers:

1

I'm learning cakephp for some time and it's very nice, I'm using the cake bake to create my classses.

Suppose I have a animal entity and a food entity and they have a many to many relation, and I'm on the add animal view, how can I add the option to add 3 new foods to this animal on this view? and what should the controller code look like in the add funciton?

A: 

Think of it like a BlogPost with Tags. To enter the tags on the entry form you'll have a text input field.

In the add/edit action of the controller, you need to explode the contents of the text input and save each one separately.

When you come to edit the BlogPost, you must join the tags into a string again so that it can be used to populate the text input field for addition or removal of tags.

This link should help: http://mrphp.com.au/code/working-habtm-form-data-cakephp

Leo