0
votes

I would like to ask for some advice on how to do something in the 'correct' CakePHP way.

I have a model named Recipes, and another model named Cookbook. The Cookbook is just a list of recipes. There are hundreds of recipes, and I want my Cookbook to contain just 10 of the entries in my recipes table.

Basically, the Cookbook only has two columns, the id and the foreign key recipes_id which references an entry from the Recipes table. Now this is where the problem begins.

Is there a better way to enter foreign keys when adding/editing the entries in my Cookbook model? The only way I can do right now is to use the default echo $this->Form->input('recipes_id');. But since my recipes run in the hundreds, the dropdown menu that CakePHP provides by default might not be the best way to do this especially when the Recipes reach over a thousand.

How do I input foreign keys without resorting to dropdown menus?

1
Use a javascript autocomplete, with a remote datasource jquery ui is a good place to start. - AD7six
The foreign key in the database should be recipe_id if you want to stick to conventions. - Nunser

1 Answers

0
votes

I agree - you likely wouldn't want a dropdown.

Here are a few ideas:

  • Alphabetical check boxes in grid format
  • Search box with ajax/javascript
  • Categorized Select boxes - ie first, they choose the type of recipe, then the sub-type, then the actual recipe.