Book Review: php|a’s Guide to Programming with Zend Framework
April 18th, 2008 by Ivo
I've recently read Cal Evans's Zend Framework book.
Before I voice my opinion, a disclaimer: I have met Cal personally; in fact I'm having diner with him next Monday, I'm writing a book for php|architect, and my company is a Zend partner. I could not be any more biased.
If you still trust my judgement (and I will try to remain objective), read on.
First of all, the book is fun to read. I like Cal's writing style. He's able to teach stuff while keeping it light and funny. And that works; the book is never dull so it's easy to read in a short time frame. (I never read things in a short time frame though, still took me a month to read it, but that's me; not the book.)
The book first covers the important bits of ZF, such as setting up a ZF application, and working with views and the controller.
What I really liked was that Cal covers the Model properly. Recently there was some fuzz: the now infamous 'heckler at the phplondon conference' called framework authors 'criminals' because they called their frameworks MVC while they only provided Views and Controllers. Cal discusses how to use both a thin model (just a wrapper for the database) and a thick model (business logic) in a Zend Framework application. The book demonstrates, with example code, that you don't need a 'Model' class in the framework itself to work with a Model. A Model is application specific anyway, it contains the business logic of the application. This was refreshing. It was almost as if it was written because of the phplondon incident but the book was written well before that.
After covering all the important bits, some less important but nevertheless useful topics are covered: caching, web services and two-step views (layouts).
The book is full of code samples, and from the book's website you can download the sample code so you don't have to copy the code from the book manually.
Of course, I also have a little criticism. In some parts of the book, things are explained rather quickly. In particular in the web services part, I had to reread some parts a few times before I grasped them. I had the feeling that the rest of the book had a calmer pace, which made it easier to understand what was explained.
Also, there were a few bugs in the book, in particular spelling. However I must be careful to say that, my book might have the same issue.
Regarding bugs in the example code; Cal keeps track of them at the book's companion site, so if you run into an issue when running the sample code, first check the site to get the latest code.
All things considered, it is a useful, well-written introduction to the Zend Framework. I can recommend anyone who just started working with the framework, and anyone considering to use it, to read the book. It will not only show you how to get things done, it will also give some insight into how the framework works and why things are the way they are, and this greatly helps to understand the framework.
My First Mashup
July 27th, 2007 by Ivo
I have been inspired by Cal Evans' mashup experiment, which he did a presentation on at the Dutch PHP Conference last month.
Also, I was annoyed with having to consult many different resources when I plan a business trip.
So I began building frekfly, my own little mashup.
Version 1
The first version, which took me only a few hours to built, offered only a google map, basic weather information, flickr images and currency conversion. To built this, I used the following tools:
- PHP5's Webservices API, which made it possible to consume webservices with only very few lines of code.
- The Flickr API to retrieve images
- Google Maps for the map display
- Some webservicex services, for weather, geographical and currency information.
- Zend Framework, mainly for its Zend_Service_Flickr class, which makes consuming the flickr rest service easy.
- ATK, for its debugging console and file-caching.
It's really easy to construct an application like this in PHP, given that a few lines of code give you access to any available webservice. The first version of the app did not even use a database, everything was retrieved from webservices and cached in files.
Version 2
Then, I wanted more. When I travel for work, I usually need hotels that are located close to the airport, so I looked for a webservice that could provide me with hotel information. I requested access to the API at expedia, but they have a manual approval process and I'm still waiting for a response. Luckily the people at booking.com were a lot more helpful and they provided me with an iframe based interface to their hotel reservation engine, and they even styled their pages according to the design (well ok, that's not really a design yet, is it
) of frekfly.
The only thing missing from their API was the ability to search by latitude and longitude, which was my close-to-the-airport criterium. However, they kindly send me a dump of their hotel database including the coordinates.
So in version 2 I had to add a database, and I used the database abstraction layer of ATK to easily access it.
Version 2 is what is currently online. I may post some code examples of the webservice interfaces later on, because I found this to be a very instructive experience.
Future plans
In the next version, I want to add other nifty web-two-point-oh features to the site, including the ability to have visitors enter comments and details, so they can help complete the airport information. (such as 'are there better restaurants before or after security?'). Here I plan to use the JSON functionality of Zend Framework, to make this very 2.0-ish.
Issues to deal with
One of the major disadvantages of mashups is the fact that you're dependent on external systems. At night, the site is hardly usable because webservicex is very busy at that time and gives a lot of timeouts. Of course, this is countered by caching, but I can't cache every output for every airport on the planet, so caching is based on a 'retrieve the first time its needed' approach. So that's a disadvantage at this point.
Another interesting issue you have to deal with when writing mashups is standardization in naming, or rather, the lack thereof. For example, I consult 2 different webservices and a few file based airport resources to get airport information, but each of them use different names for the same airport. Where possible, I use the official 3-letter IATA code, but some of them do not support that.
So instead of actually matching data from different sources, you have to use a more probabilistic approach, where you say "hmm, 'Schiphol Airport Amsterdam' and 'Amsterdam, Schiphol' are probably the same airport.
I had a similar issue with the weather service; it doesn't support latitude and longitude, so what it does is 'guess' what the nearest weatherstation is, based on the airportname, the nearest town name, the biggest city close to the airport and finally the country capital if all else fails.
These are all issues to deal with in a mashup-based application, and I would encourage everyone to built a mashup at some point, because it teaches you things that you don't usually encounter with standard mysql+php based websites.
What php search engine would you use?
March 8th, 2006 by Ivo
I'm facing a challenge with a customer running a site we built on a hosting environment that is quite restrictive. We used to use htdig to add search functionality, but the hoster doesn't allow execution of binaries.
I've taken a look at several search engine implementations, but so far, none match all requirements:
- Zend Framework's lucene search: requires PHP5, but we have to run it on PHP4
- phpdig: uses exec() to perform the search, but we are running in safe mode
- google: layout not flexible enough
- htdig: requires execution of binaries, which is not allowed
- perlfect: requires execution of perl, which is not allowed
Maybe isearch is an option but I cannot find a lot of info about it.
The requirements are simple, but restrictive:
- Should be usable/integratable in a PHP4 based site
- Should run with safe mode on
- Layout should be customisable
- Should not require execution of perl or binaries, at least not for the search part (uploading an index that is created on a separate machine is somewhat acceptable although not prefered)
- Should be spider based, so no database query based search engine
Free Software/Open Source/Free as in Free Beer would be nice, but is no strict requirement.
Anybody any suggestion? What are you guys using?
Quick Zend Framework review
March 5th, 2006 by Ivo
This weekend I've taken a look at the initial release of the Zend Framework.
The first thing I've noticed is that authors of frameworks can sleep soundly again
, as the zend framework is not yet a framework (in the wikipedia sense of the word).
Currently, it's more a component library containing all kinds of useful components. This does not have to be a disadvantage though, because this makes it very easy to integrate with other applications and existing frameworks. In fact, there are some components such as the pdf and mail classes that are very useful for certain types of web applications, and it is fairly easy to use them in an application that was built using an existing framework.
People expecting a kind of 'ruby on rails' for php have to wait a little longer though, as the Zend Framework is not there yet.
When diving into some of the classes, there are some decisions that I don't quite understand. For example, have a look at Zend's implementation of isReadable. It is a wrapper for PHP's is_readable, with the addition of also taking the include path into account. Since this is a very useful feature in many occasions, why not enhance PHP's is_readable function with this functionality? Especially since it's just a small enhancement, so in my opinion, it would be better to put this directly in PHP, instead of in wrappers. (the same goes for some of the other framework methods that are wrappers for some existing functionality.) Putting stuff in wrappers is, in my opinion, a bad way of enhancing functionality. Suppose wrapper 1 adds functionality A, and wrapper 2 adds functionality B. If I'm in a situation where I need both A and B, I have to take one of the wrappers and implement the other feature myself. So in the case of 'low level' methods such as this, I'd rather have the functionality in the base function instead of in a thin wrapper.
Another functionality I have some doubts about is the registry. It is advertised as a method to handle singletons. In my opinion, the fact whether a class is a singleton should be handled by the class itself. The application author should normally not need to make the decision whether some class he is using should be a singleton or not. Also, the concept of a singleton's getInstance() method ('give me an instance or create one of there isn't an instance yet') seems to be lost in the zend framework registry, as there is no such method and the application author needs to define his own 'if it's not in the registry yet, add it' logic.
The RSS feed functionality is nice, and would be even nicer if it had methods for creating feeds instead of consuming them. This type of functionality however is typically something that would be useful to have available as a separately downloadable, dedicated library instead of as a standard part of the framework.
The other components all seem useful and nice too. There are definitely components that I'm going to use in applications I'm working on.
Overall, the Zend Framework looks promising. I think that at the current state, the zend framework falls in the category of libraries such as PEAR and ezComponents. All of them provide a wide choice of generic components. I think the stuff that would make it an actual framework are still missing, (but the model/view/controller classes are a step in that direction), but this has the major advantage that frameworks such as Blueshoes and ATK are not actually competition, but potential users of the zend components.
Nerd Puzzle
October 18th, 2005 by Ivo
Ok, this post has no use whatsoever, but I need to get this out of my system. I was in an incredibly dull meeting the other day, and at one point, I had on my sheet of notes 3 randomly placed dots:
.
.
.
For some reason, I don't know why, I started to wonder if there would be one or more circles that have an outline that touches these 3 dots. Yes I am a nerd (just imagine how boring the meeting was).
To put this puzzle in other words: is there, for any given set of 3 points, a 4th point that has an equal distance to the first 3 points?
My preliminary conclusion is that for each three points, there is exactly 1 circle that has a matching outline, unless the 3 points are positioned exactly in one line. I lack the mathematical background however to prove/disprove this in theory. I discussed this with a fellow nerd and he also concluded that there should be exactly 1 circle for each set of 3 points (as long as they are not in a straight line).
Now I'm curious. Am I right in the 'exactly 1 circle' assumption? If so, what would be the optimal way of determining the center of the circle? In other words, how would you implement:
/** * Determine the center point of a circle whose outline strikes 3 given points. * @param Point $a * @param Point $b * @param Point $c * @return Point The center point of the circle outlining point $a, $b and $c */ function centerpoint($a, $b, $c) { .... return new Point($x, $y); }
On to something else. The rumours of the Zend Framework are spreading quickly. I haven't been contacted by Zend so it's not going to be Zend ATK.
I'm wondering what it is though. Whether it's anything like a business framework, or more of an IDE kind of thing, or just a set of classes providing some API.
Finally an update on ATK: we're wrapping up RC1 of ATK 5.3. It should be out real soon now.