Easy way to use Zend Framework in CakePHP

More cursing this morning as I tried to integrate Zend Framework’s GData within my project. After a bit of trial and error I came across this simple easy solution:

1. Save the ZF folder as Zend in your [app]/vendor folder
2. Create a file named zend_include.php in your [app]/vendor folder and paste the following code in it:
ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . dirname(__FILE__));
3. To use in Cake, do this:
App::import('Vendor', 'zend_include');
App::import('Vendor', 'Zend_Gdata_YouTube', true, false, 'Zend/Gdata/YouTube.php');

(Replacing Gdata_YouTube and /Gdata/YouTube.php with the proper Zend Library you’re trying to use)
4. You can then call
$zend = new Zend_Gdata_Youtube(); // etc

I wish I could take full credit for this but it was this comment that finally got me on my way.

Quick tip for the form helper in CakePHP when editing

While working on my latest crazy idea, I was testing the edit function of a particular section and realized something alarming:

If I had an error while editing, the form helper was changing my /edit/id form URL to /add!

I could not for the life of me figure out what the problem was. After an hour of various curses and attempts to correct the issue, I stumbled across this little bit of information:

You need to add a hidden id field with the id for the record as the value in order for the edit URL to persist. D’oh!

I simply added this to all my edit views and voila! It worked! Hopefully this will help someone else 🙂