Singletons are often compared to same class of evil as goto instruction, or more familiar for PHP developers $GLOBALS. This thesis is hard to understand since Singleton is most basic and commonly know pattern. Even if one agrees with arguments, might find hard to eliminate singletons from own code. Giorgio Sironi shows that eliminating singletons is not that hard.
It is actually very simple to eliminate singletons: just force the components to ask for what they need in the constructor or via setters or via inject*() methods, instead of looking up a singleton trough a static method only to obtain a reference. Once this fundamental decoupling is achieved, the hard part is tackling the construction problem: Zend Framework has a big codebase and writing a factory (manual dependency injection) for every use case is not viable. Thus, automatic dependency injection needs to be called upon. There are many xml-configured dependency injection frameworks for php to incorporate, but let’s show a simple example of how they works.
The tutorial was split into two parts. First one presents basic solution for the problem. Second part addresses some problems related to objects having shorter lifetime than application-wide ones.
Information about new webminar has been published on Zend website:
Zend_Form provides powerful management of filter and validation chains, as well as the ability to render the form and its elements. The approach to rendering is via a flexible decoration system that often takes some time to understand.
In this webinar, we’ll look at how you can start writing decorators as well as leveraging existing decorators to render complex form markup.
Webminar will take place on December 16th.
TechChorus is technology blog maintained by Sudheer Satyanarayana. On of recent posts written by Sudheer is quick start Zend_Rest tutorial.
The Zend Framework 1.9 release added a new feature – Zend_Rest_Controller. Zend_Rest_Controller and Zend_Rest_Route classes go hand in hand. In the previous versions of the Zend Framework, we have had the Zend_Rest_Server component. We still have. Since Zend_Rest_Server provides an RPC like component violating the REST architectural constraint, it is likely to be deprecated in the future versions of the Zend Framework.
Sudheer shows how to use new Zend_Rest classes to create simple REST service. Although controller’s actions are hardcoded, the tutorial itself purpose is just to show how to create and call a REST service. Don’t forget to read comments too, especially from Matthew Weier O’Phinney about HTTP response codes.
Doctrine is slowly getting more and more popular among Zend Framework developers. Since development of Zend_Entity is dropped in favor of Doctrine integration, it’s popularity should not be surprised. Especially that it is solid ORM-like tool. One of Doctrine integration evangelists is Jouzas Kaziukenas.
So about 3-4 months ago I completely switched to Doctrine. After evaluating possible solutions I decided to stay with Doctrine for a long time. I don’t know any other solution coming, I definitely don’t want (mainly because I don’t have time) to invest on creating my own library and Doctrine is simply awesome when you get used to it. After all this time I can say that it was a right call – Doctrine is on a way to being officially supported in Zend Framework (Symfony has it right now) and with Doctrine 2.0 (you can see a short presentation of its new features right here) it will be just a perfect tools combination.
He begun publishing series of posts about his experience in Doctrine and Zend Framework integration. First two parts of the series cover brief description of Doctrine and it’s capabilities, setting up Doctrine resource, creating database, models and executing simple query.
Almost all Zend Framework tutorials suppose that reader is using Apache webserver with mod_rewrite module. For those who work with II6, without ISAPI_Rewrite module, Rob Allen wrote post about setting up URL rewriting for Zend Framework.
IIS6, which ships with Windows Server 2003 does not have this module though and guess which version my client’s IT dept run? As usual, they wouldn’t install ISAPI_Rewrite or one of the other solutions for me. In the past, I’ve simply written a new router that creates URLs with normal GET variables, but this is ugly and I wanted better.
Rob shows how to configure the server to call single script, index.php, upon 404 error and use his request class to grab request and forward back to desired location.