cakephp 2, editing form creates a new record instead of updating it

cakephp

Solution

If you have used the console to bake your Views, your Edit forms should have this line:

echo $this->Form->input('id');

If it is not present, you should add it. This ensures that the id of the Object you are saving is present in the data sent to the Controller and then to the Model so it does not create a new record in the database.

Problem

I'm using the console cake bake to generate forms automatically from the database. I have a problem though, one of my controllers instead of updating a record after editing it, is creating a new record into the database.

Original source