Zend Framework inside CakePHP 1.2
Posted on October 12th, 2008 in CakePHP, Php, Programming | 4 Comments »
Zend Framework’s beauty is it’s range of services or web API, like Delicious, Flickr, GData and a lot more. build into it by default. CakePHP’s beauty is that you can extend it, extend it way up to the point where you can import other framework and make use of that framework’s feature. Having said that, Zend inside CakePHP would be totally awesome. The inspiration behind was this blog post http://britg.com/2008/07/07/using-the-zend-framework-in-cakephp/ but i will show you how to use the flickr service.
First download the minimal version of Zend Framework (It will ask you 2-3 times on what you want to download and will ask for you to login/register and i think this is insane). Anyway after downloading extract the files to your folder so that you will have a folder structure like
vendors
---Zend
------Everything that is inside the folder library/Zend
After that, as what britg.com said about the config file, import the following lines in core.php
ini_set('include_path',ini_get('include_path') . PATH_SEPARATOR . '/path/to/vendors/');
Then you’re ready to use Zend’s feature in cake.
function getArtistImage($id){
$this->Artist->id = $artistId;
$artistData = $this->Artist->read();
if($artistData){
App::import("vendor",'Zend_Service_Flickr',array("file"=>'Zend/Service/Flickr.php'));
$flickr = new Zend_Service_Flickr('your flickr api key');
$artistName = $artistData['Artist']['name'];
$results = $flickr->tagSearch($artistName);
$this->set(compact("results","artistName"));
}
}
Then in your view
<? foreach ($results as $result): ?>
<img src="<?=$result->Small->uri;?>"
height="<?=$result->Small->height;?>" width="<?=$result->Small->width;?>"
>
<? endforeach; ?>
To further explain a bit
App::import(“vendor”,’Zend_Service_Flickr’,array(“file”=>’Zend/Service/Flickr.php’));
– this imported the flickr api
$flickr = new Zend_Service_Flickr(‘your flickr api key’);
– this creates a new instance of the flickr service
$artistName = $artistData['Artist']['name'];
$results = $flickr->tagSearch($artistName);
– this searches the artist’s name on the tags on flickr
Here is an example of this post
http://monmonja.com/music/lyrics/flickr/87

4 Responses
[...] Monmonja Music Blog » Blog Archive » Zend Framework inside CakePHP 1.2 A very succinct tutorial on using Zend classes inside a CakePHP application (tags: cakephp zend tutorial) Posted by Richard@Home Filed in 15 [...]
Thanks for writing about this. I’ve been searching for the past half hour.
1. Are there Zend files that I can exclude in the Zend directory? The minimal library files are 20 MB!
2. How do you find the performance when integrating Zend? I’m just kind of worried about the performance hit.
Thanks again for the write up. I’m going to try it out!
[...] But if what you are looking is not there or even when you google it check this link Using the Zend framework inside CakePHP [...]
Heya! I’ve once written a simple component to do exactly the same. It’s a bit old, but feel free to tune it in case it’s outdated. Haven’t used ZF for a while.
Code at: http://bakery.cakephp.org/articles/view/zend-framework-loader-component