Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Building PHP Applications with Symfony, CakePHP, and Zend Framework
This is the forum to discuss the Wrox book Building PHP Applications with Symfony, CakePHP, and Zend Framework by Bartosz Porebski, Karol Przystalski, Leszek Nowak; ISBN: 978-0-470-88734-9
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Building PHP Applications with Symfony, CakePHP, and Zend Framework section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 3rd, 2011, 09:47 AM
Registered User
Points: 17, Level: 1
Points: 17, Level: 1 Points: 17, Level: 1 Points: 17, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2011
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Default Chapter 4 - CakePHP Form ID Passing fix

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.
Reply With Quote
  #2 (permalink)  
Old April 6th, 2011, 03:55 AM
Registered User
 
Join Date: Apr 2011
Posts: 3
Thanks: 0
Thanked 1 Time in 1 Post
Default

Following code is obviously wrong:
Code:
echo $form->create('Address', array('action' -> 'edit'));
It is a simple printing mistake in the book's code listing, for which we are truly sorry, but our downloadable source code is correct. The correct code for this one is, as you noticed:
Code:
echo $form->create('Address', array('action' => 'edit'));
The other problem is of somewhat different nature, and we are afraid You may have some other issues related to this one, because the examples in our book are based on Cake 1.2.

Here are two examples from the CakePHP documentation:

The first one is for CakePHP version 1.2 (the stable release while we were writing this book) :
Code:
<?php echo $html->link( $post['Post']['title'], array( 'action'=>'view', 'id'=>$post['Post']['id'] ) ); ?>
The second one is for CakePHP version 1.3:
Code:
<?php echo $this->Html->link( $post['Post']['title'], array( 'action' => 'view', $post['Post']['id'] ) ); ?>
As You can see, your solution uses CakePHP v.1.3 syntax.
Code:
link($address['first_name'],  array('action'=>'view', $address['id']))
We thank You for Your contribution :)
Reply With Quote
The Following User Says Thank You to BartoszPorebski For This Useful Post:
Akira71 (April 6th, 2011)
  #3 (permalink)  
Old April 6th, 2011, 07:20 AM
Registered User
Points: 17, Level: 1
Points: 17, Level: 1 Points: 17, Level: 1 Points: 17, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2011
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thank you for clearing that up BartoszPorebski. I now see why there was a difference and what was causing the confusion.

I had just picked up the book, great idea on the book by the way showing how several different frameworks implement the same thing, and was working through it this past weekend. Of course I downloaded the latest stable release of CakePHP and did not even think about version differences. Now I know to check for the differences. I am still learning and these tips all help me out.

Again, thank you for writing a good book and helping newbies in PHP such as myself gain a deeper understanding.
Reply With Quote
  #4 (permalink)  
Old April 6th, 2011, 07:40 AM
Registered User
 
Join Date: Apr 2011
Posts: 3
Thanks: 0
Thanked 1 Time in 1 Post
Default

I'm glad you like our book, and thank you for buying it in the first place.

We've put much effort to make it as good as possible, but some mistakes are unavoidable. We count on good reviews, so if you find any other bugs we'll do our best to patch them up.

The issue with versions is even worse - you write something one day, and the next day it's obsolete. We had such problem with Google Web Search API. Karol wrote a chapter about it in October 2010 and I reviewed it a few days later in November only to find it became deprecated in the meantime. So we had to rewrite that part ;)

Good luck and have fun!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing ID query rsm42 ASP.NET 1.0 and 1.1 Basics 2 January 7th, 2007 10:45 AM
New Chapter 3 Fix .MAttButler BOOK: Professional Web Parts and Custom Controls ASP.NET ISBN: 0-7645-7860-X 0 August 14th, 2006 09:08 PM
Passing the Id to another form louie001 ASP.NET 1.0 and 1.1 Basics 1 July 14th, 2006 06:45 AM
passing session Id via email ? Gotaka4 Pro PHP 2 March 30th, 2005 09:24 AM
Passing a variable into the id() function EstherMStrom XSLT 5 January 19th, 2005 02:32 PM



All times are GMT -4. The time now is 08:33 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.