Pragmatism in the real world

Evan Coury: Module-specific layouts in Zend Framework 2

Evan Coury has posted Module-specific layouts in Zend Framework 2 First, I should point out that the title of this post is a bit of an intentional misnomer. There’s really no such thing as “module-specific” anything in ZF2, so what we’re really talking about is the topmost namespace of the controller being dispatched. So in the case of MyModuleControllerSomeController, the topmost namespace would be MyModle. In most cases, this will be the name of a… continue reading.

Vagrant in Zend Framework 1

I recently added support for vagrant to the Zend Framework codebase to enable easier testing. I was motivated by some work the joind.in folks have done to get a working development environment for joind.in development using Vagrant. Vagrant is a fantastic tool that enables you to manage and run virtual machines from the command line, including automatic provisioning of them using puppet or chef. The really cool thing about it however from my point of… continue reading.

Unit testing Zend Framework 1

As part of our release process for Zend Framework 1.12, I've been working through the unit tests and running them on PHP 5.2.4 as it seems that recent changes weren't being tested with that version. This isn't totally surprising as Open Source contributors are, almost by definition, interested in new things and so are much more likely to be running PHP 5.4 rather than 5.2! This is, of course, a compelling reason for using continuous… continue reading.

Evan Coury: Sharing a database connection across modules in Zend Framework 2

Evan Coury has posted Sharing a database connection across modules in Zend Framework 2 » Evan's Blog With the new modular infrastructure in Zend Framework 2, one of the most common questions will indoubitably be how to share a database connection across modules. Here’s a quick explanation of how to share your database connection across multiple modules in a way that can even allow you to use a single connection between ZendDb, Doctrine2, and possibly… continue reading.

An introduction to ZendEventManager

Zend Framework 2's EventManager is a key component of the framework which is used for the core MVC system. The EventManager allows a class to publish events that other objects can listen for and then act when the event occurs. The convention within Zend Framework 2 is that any class that triggers events composing its own EventManager. Terminology For the purposes of this article, we will use these definitions: An EventManager is an object that… continue reading.

Getting started with Natural Load Testing

I've been following the products of WonderNetwork for a while as they do some interesting stuff with servers around the world. I particularly like Wonder VPN as a drop dead simple and reliable VPN is very handy for any mobile user who wants some security when using a wireless network in Starbucks! Recently they have been working on a new product called Natural Load Testing which is intended to make load testing your web application… continue reading.

Access view variables in another view model

Unlike Zend Framework 1, the view layer in Zend Framework 2 separates the variables assigned to each view model. This means that when you are in the layout view script, you don't automatically have access to variables that were assigned the the action's view model and vice versa. Accessing action variables in the layout Consider this controller code: class IndexController extends ActionController { public function indexAction() { return array('myvar' => 'test'); } } If you… continue reading.

Returning JSON using the Accept header in ZF2

2 December 2012: Note that as of ZF2.0.4, this no longer works due to changes to fix a security issue. See the release notes for further information. Following yesterday's article on returning JSON from a ZF2 controller action, Lukas suggested that I should also demonstrate how to use the Accept header to get JSON. So this is how you do it! Set up the JsonStrategy We set up the JsonStrategy as we did in returning… continue reading.

Returning JSON from a ZF2 controller action

The new view layer in Zend Framework 2 can be set up to return JSON rather than rendered HTML relatively easily. There are two steps to this: Set up the JsonStrategy Firstly we need to set up the view's JsonStrategy to check to a situation when returning JSON is required and then to render out JSON for us. The JsonStrategy will cause the JsonRenderer to be run in two situations: The view model returned by… continue reading.

Automatic Apache vhosts

One thing that I've wanted to implement for a while now is automatic vhosts on my dev box. The idea is that I want to drop a folder into a directory and have it automatically turned into a vhost for me accessible at http://foldername.dev. It turns out that this isn't nearly as hard as expected which is usually the case with things that I've been putting off! This is how to do it. Apache configuration… continue reading.