Using Zend framework Components In CakePHP
|
|
|
Click to rate: |
|
|
|
78 votes / avg. rating 16.74%
|
|
In this article I describe how to use Zend framework components in a CakePHP application by means of building a very simple CakePHP application using Zend_Service_Flickr, a component for accessing the Flickr web services.
Before we can start baking we have to do some preparations. First of all, this article is for those who are at least familiar with using CakePHP at a very basic level. If you are not yet introduced to CakePHP, please check out the Overview on CakePHP by Fabio Cevasco here at A/R/T. Now, onto the actual preparations: 1. Make sure you installed PHP 5 as the Zend framework requires PHP 5. 2. I assume you have already installed CakePHP. If that is not the case, download it from http://cakeforge.org/projects/cakephp/ and follow the installation instructions on http://manual.cakephp.org/chapter/3. I used version 1.1.6.3264 of CakePHP for this article. 3. Download the Zend framework from http://framework.zend.com/download. 4. Copy the content of the directory ZendFramework-0.1.5/library from the zipped file to <where_you_installed_cakephp>/app/vendors. With that, the preparations are done. We are ready for baking our cake. Baking, first iterationIn our first iteration we will build the skeleton of our application. Our goal is to get an empty page when calling our controller. Yes, I know, the result of an iteration should be something of value for the user, so this iteration is an exception.
We start with the model which we call simply “Flickr”. What functionality should our model provide? For our simple application we only need one method which returns images for a tag. So we get the following class:
// app/models/flickr.php
class Flickr extends AppModel
{
var $useTable = false;
function getImagesByTag($tag)
{
}
}
Notice that we have to add “var $useTable = false;” as our model will use a webservice and not a table.Our model will be used, of course, by a controller. To make use of CakePHP's magic we name it “FlickrController”. The functionality of our controller is simple: it needs a method which gets the data from the Flickr model and hands the data over to the view. So we can write our controller:
// app/controllers/flickr_controller.php
class FlickrController extends AppController
{
function show($tag = null)
{
$this->set('images', $this->Flickr->getImagesByTag($tag));
}
}
The last step is the view. It is self-explanatory.
// app/views/flickr/show.thtml
foreach ($images as $image)
{
}
Our first iteration is almost done. Time to test what we have done. Open <yourdomain>/flickr/show/tree in your browser and you should get an empty page. Not really interesting, is it? So we move directly to the second iteration.
 |
|
 |
|
Tags:
zend framework, cakephp
Tags Help
Tags are keywords associated with a web page that help classifying information. You can find a good explanation here.
To add one or more tags to this page, simply enter them below (separate them with a comma) and hit enter or click on the "Go" button.
|
|
 |
|
 |
|