Padraic Brady’s Blog: Interfacing The PHP World Would Be Good
Oct 27, 2011 php, Zend Framework
Padraic Brady has posted his own response to some of the recent talk about making standard interfaces in PHP applications. His perspective focuses on interfaces and coupling as related to the Zend Framework.
Every PHP framework has it’s own unique set of interfaces for common operations such as logging, caching, http clients, filtering, validation, etc. This creates a situation where a framework tends to be loosely coupled but only within the scope of its own interfaces. [...] Loose coupling is therefore a bad joke. It is a narrowly defined concept usually described within the scope of one particular application. We never really apply the concept across multiple applications written with different frameworks because, at that point, the disparate interfaces of both frameworks would immediately make loose coupling unobtainable.
He goes on to talk about a simple example, ZendFeedReader, and how it’s very difficult to swap something as simple as the HTTP client out for one from another framework. He mentions the common scapegoat for over-interfacing – Java – and how PHP’s is a bit more “practical and flexible” in that department (a good and bad thing).
So yes, common interfaces would benefit PHP and would make framework libraries more interoperable and thus usable within competing frameworks. Hey, if you can’t beat them at least make sure you can inject your classes into them. Hmm, still sounds dirty.
Tags: php, zend framework
Robert Basic’s Blog: A Zend Framework 2 EventManager use case
Oct 20, 2011 php, Zend Framework
Robert Basic has a new post to his blog today with an use case for Zend Framework 2′s event manager to solve a problem he has with “repetitive code” in some of his models.
Basically, this allows us to have one piece of code to trigger an event and to have one or more listeners listening to this event. When the event gets triggered, the listeners are called and then we can do *something*, like caching or logging. Logging or caching. [...] See, that’s my problem. All the event examples stop at logging and caching. Truly there must be some other example for which this event stuff can be used for.
In his example code, he’s used the EventManager in one of his models to add listeners to validate the post and “slugify” the post’s title for use on the URL. You can find his code on github if you’re interested in the full implementation.
Tags: php, zend framework
Community News: Zend Announces phpcloud.com (development/deployment platform)
Oct 20, 2011 php, Zend Framework
As mentioned in this post to The Register, Zend, a large player in the PHP market, has announced their own cloud-based platform for deploying PHP-based applications – phpcloud.com.
Zend has announced a cloud for building and deploying PHP apps on other clouds – but without the management hassle. The PHP specialist has announced phpcloud.com, which it said was a technology platform and a partner ecosystem based on the company’s Zend Framework and Server. Details are vague, but the technology platform consists of Zend App Fabric and Zend Developer Cloud. The App Fabric uses the Zend Framework – a library of loosely coupled PHP components – with Zend’s PHP stack and management and diagnostics tools.
The platform comes with features for caching, job queuing, high availability and code traces (among others). It plays especially nice with Zend’s Studio development tool. The site, phpcloud.com has full details on what the platform offers and how you can get started with it quickly and easily with a free developer account.
Tags: php, zend framework
Uploadify on Zend Framework and the 302 error
Oct 20, 2011 php, Zend Framework
Uploadify is an awesome script and it works like a charm. But – there’s always a but – sometimes it throws a mysterious 302 error. This happened to me all day long and it drove me crazy. Well, not really, I was already crazy
So, what to do when the HTTP 302 error pops? A quick look over HTTP statuses should point the me in the right direction:
The requested resource resides temporarily under a different URI. Since the redirection might be altered on occasion, the client SHOULD continue to use the Request-URI for future requests. This response is only cacheable if indicated by a Cache-Control or Expires header field.
The temporary URI SHOULD be given by the Location field in the response. Unless the request method was HEAD, the entity of the response SHOULD contain a short hypertext note with a hyperlink to the new URI(s).
If the 302 status code is received in response to a request other than GET or HEAD, the user agent MUST NOT automatically redirect the request unless it can be confirmed by the user, since this might change the conditions under which the request was issued.
from here. In simple English, that means a redirect. So what happens!? For security reasons, I turned on the cookie-httponly setting and the client-side script was unable to access the cookies and pass the session id back to the server-side script, which in term would see this connection as coming from an non-authenticated user and issue a redirect to the login page. Thus the mysterious 302 status.
The problem can be solved really easy, by turning the cookie-httponly setting off for the entire application. If that’s not desirable, there’s a more complicated solution. First, Uploadify must send the session id to the server together with the file:
$('#fileUpload').uploadify({
'uploader' : '/uploadify/uploadify.swf',
'script' : '/images/upload/',
'cancelImg' : '/uploadify/cancel.png',
'auto' : true,
'fileExt' : '*.jpg;*.gif;*.png',
'fileDesc' : 'Image Files',
'sizeLimit' : 2097152,
'scriptData' : {'sid' : '<?=Zend_Session::getId();?>'},
onComplete : function(event, id, fileObj, response, data) {
// bla bla bla
}
}
…then, turn off the auto-start in the application.ini file:
phpSettings.session.strict = "On"
…and in the Bootstrap.php file:
protected function _initSession()
{
if (isset($_POST['sid'])) {
Zend_Session::setId($_POST['sid']);
}
Zend_Session::start();
}
Of course, there are some security issues with both approaches, but nothing serious. Took me about 2 hours to figure it out
Tags: javascript, php, Uncategorized, zend framework
Rob Allen’s Blog: Updated tutorial for Zend Framework 2 beta 1
Oct 19, 2011 php, Zend Framework
Rob Allen has a quick note for fans (or those just discovering) his “Getting Started with Zend Framework” tutorial – he’s posted an updated version for ZF2 beta 1.
Getting started with Zend Framework 2 (beta1), creates the same application as my ZF1 tutorial, so it should be very familiar, but this time, it’s in the context of Zend Framework 2. As usual, it’s a PDF too.
This latest version gives you a gentle introduction to the framework and steps you through the creation of a sample music inventory system. It includes code and explanations of how set up modules, controllers, models and views and how to tie them all together. If you’re new to the framework and want to get off and running quickly, I’d highly recommend his tutorial.
Tags: php, zend framework
Updated tutorial for Zend Framework 2 beta 1
Oct 18, 2011 php, Zend Framework
With the announcement of Zend Framework beta 1, I have updated my venerable tutorial to work with it!
Getting started with Zend Framework 2 (beta1), creates the same application as my ZF1 tutorial, so it should be very familiar, but this time, it’s in the context of Zend Framework 2. As usual, it’s a PDF too.
Please download it, try it out and let me know if you find any typos!
Tags: php, zend framework
Zend Framework 2.0.0beta1 Released! – Zend Developer Zone
Oct 18, 2011 php, Zend Framework
The Zend Framework community is pleased to announce the immediate availability of Zend Framework 2.0.0beta1. Packages and installation instructions are available at: http://packages.zendframework.com/
Tags: php, Top stories, zend developer zone, zend framework
Reddit.com: Which MVC framework has the best documentation and u…
Oct 14, 2011 php, Zend Framework
On Reddit.com there’s a new post that asks the question, “which framework has the best documentation and community?”
About to dive into MVC and wondering which one has the most wealth in terms of documentation/code comments as well as a decent community.
Suggestions in the comments include both old and new options including:
Tags: code comments, community suggestions, decent community, php, Top stories, zend framework
Padraic Brady’s Blog: Zend Framework 2.0: Dependency Injection (…
Oct 13, 2011 php, Zend Framework
Padraic Brady is back today with the second part of his “Dependency Injection in Zend Framework 2.0″ series. In this second post he talks about what dependency injection containers are (and aren’t) and how they could lead to bad practices if they’re considered as service locators.
Tags: object relationships, padraic, php, pimple, service locators, Top stories, zend framework
Padraic Brady’s Blog: Zend Framework 2.0: Dependency Injection (Part 2)
Oct 13, 2011 php, Zend Framework
Padraic Brady is back today with the second part of his “Dependency Injection in Zend Framework 2.0″ series. In this second post he talks about what dependency injection containers are (and aren’t) and how they could lead to bad practices if they’re considered as service locators.
For Part 2, we’re going to dig more into what a DIC is and isn’t. I’ve already noted one very simple DIC called Pimple which will continue as one of my reference points since it best illustrates just how simple a DIC can be. In Part 3, we’ll (finally) turn our attention to some actual source code. Baby steps. Parts 1 and 2 should get you thinking so that ZF 2.0′s DIC is a lot easier to understand and critique. We don’t want anyone panicking just by throwing them into the deep end.
He talks more about the Pimple DIC tool and how, despite it’s similarity to a set of Factory pattern calls, it’s slightly different – think of it as “a container of executable Factories”. He introduces the concept of a Service Locator, an object that can find and load other objects in an intelligent way. He notes that the most ideal DIC is an “external agent” that defines the object relationships outside of the application.
He points out a feature of ZF2 that allows for injection of the DIC into a controller, allowing it to look up the resources it needs. This of course, has issues – three that he mentions specifically:
- Firstly, this isn’t Dependency Injection.
- Secondly, it creates objects which are useless without the specific DIC interface it depends on.
- Thirdly, DICs are really bad Service Locators.
Tags: php, zend framework

