Pragmatism in the real world

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.

OS X Tips and Tricks

It's been around 18 months since I wrote up some notes about OS X, so clearly it's time for an updated article. This article is intended to give a quick and easy introduction to some key things that I think you should know when you move to using OS X. Basics There's one menu bar for all applications. That is, you can only see the menus for the currently active application. Closing the last window… continue reading.

A list of ZF2 events

Both the Module Manager and the MVC system use the Event Manger extensively in order to provide "hook points" for you to add your own code into the application flow. This is a list of the events triggered by each class during a standard request with the Skeleton Application: Module Manager Zend\Module\Manager: loadModules.pre For every module: Zend\Module\Manager: loadModule.resolve Zend\Module\Manager: loadModule Zend\Module\Manager: loadModules.post Application Successful: Zend\Mvc\Application: bootstrap Zend\Mvc\Application: route Zend\Mvc\Application: dispatch Zend\Mvc\Controller\ActionController: dispatch (if controller extends… continue reading.

Ralph Schindler: PHP Constructor Best Practices And The Prototype Pattern

Ralph Schindler has posted PHP Constructor Best Practices And The Prototype Pattern If your knowledge of constructors ends with “the place where I put my object initialization code,” read on. While this is mostly what a constructor is, the way a developer crafts their class constructor greatly impacts the initial API of a particular class/object; which ultimately affects usability and extensibility. After all, the constructor is the first impression a particular class can make. In… continue reading.