I noticed when I was working through the examples, including the downloaded examples, there were errors. In case anyone is is having problem with the CakePHP code, let me suggest the fixes below:
On page 110 in the book, makes sure line 2 of the edit code looks like this:
Code:
echo $form->create('Address', array('action' => 'edit'));
Note the use of => instead of the books -> . This will fix one issue. The downloaded code had this correct.
The other problem is the way links are built for editing, viewing and deleting. If you follow the book and downloaded code you will always have a null $id. Instead use the following format for building links:
Code:
link($address['first_name'],
array('action'=>'view', $address['id']))
It's important to note that I removed the
Code:
'id'=>$address['id']
instead opting for the straight $address['id']. The reason? Your links will be correct. The incorrect format makes the link parameters look like this
Code:
http://localhost/cake/addresses/edit/id:1
instead of the correct
Code:
http://localhost/cake/addresses/edit/1
. If you follow the book chapter four, the ID will always be null because of this. Make the suggested correction above and you can view, edit and delete no problem.
I hope this helps someone out. Took me 30 minutes to figure this out, since I am still learning CakePHP.