Pragmatism in the real world

ZendCon 2014: Zend Framework 2 Certification Launchpad

Give yourself a refresher in Zend Framework 2 before taking the certification right here at ZendCon. This tutorial is designed to take developers who are well versed in ZF2 to the point where they are confident in passing the ZFCA exam. This tutorial will refresh your knowledge of some of the more widely used components, but will also cover some edge cases that you may have never used (or forgotten about). I'll also be giving… continue reading.

Using ZF2 Forms with Twig

Following on from looking at how to integrate Zend Framework 2 forms into Slim Framework, let's look at the changes required if you also happen to want to use Twig. When it comes to rendering the form, we would want our template to look like this: <form method="POST" role="form"> <div class="form-group"> {{ formRow(form.get('email')) }} </div> {{ formElement(form.get('submit')) }} </form> The ZF2 view helpers, formRow and formElement now look like Twig functions, however we don't want… continue reading.

Integrating ZF2 forms into Slim

Let's say that you want to use Zend Framework 2's Form component outside of ZF2 itself. In this case, a Slim application. It turns out that Composer makes this quite easy, though there's quite a lot of code involved, so this is a long article. Start with a really simple Slim Application. index.php: require 'vendor/autoload.php'; $app = new \Slim\Slim(); $app->map('/', function () use ($app) { $app->render('home.php', array( 'form' => $form )); })->via('GET', 'POST'); $app->run(); templates/home.php:… continue reading.

Globally overriding validation messages for ZF2 forms

One thing that I always do when creating a Zend Framework 2 form is override the validation messages for a number of validators – EmailAddress in particular. I recently decided that I should probably sort this one out once and be done with it. Turns out that it's quite easy assuming that you use the FormElementManger to instantiate your forms. All that I need to do is create my own validator classes that extend the… continue reading.

Creating a ZF2 form from config

I have a requirement to create a Zend\Form from a dynamically created array which means that I can't use the FormAbstractServiceFactory and so will use Zend\Form\Factory directly. If you need to override any form elements, validators or add new ones, then you'll need the correct plugin managers for the factory. The way to set this up is like this: $factory = new Factory(); $formElements = $this->serviceLocator->get('FormElementManager'); $factory->setFormElementManager($formElements); $inputFilters = $this->serviceLocator->get('InputFilterManager'); $factory->getInputFilterFactory()->setInputFilterManager($inputFilters); Your $factory is now… continue reading.

Injecting dependencies into your ZF2 controllers

When starting working with Zend Framework 2, it's common to copy the skeleton and put your controller definitions in module.config.php like this: 'controllers' => array( 'invokables' => array( 'Application\Controller\Index' => 'Application\Controller\IndexController', 'Application\Controller\Blog' => 'Application\Controller\BlogController', ), ), The controllers keyword is picked up by the ControllerManager which is an instance of the ServiceManager which means that it creates the controller instance for you when the dispatcher needs it.

Implementing a ZF2 development mode

One feature that piqued my interested in the Apigility skeleton application was development mode. From the README: Once you have the basic installation, you need to put it in development mode: cd path/to/install php public/index.php development enable # put the skeleton in development mode

ZendCon Europe 2013: Zend Framework 2 tutorial

This half-day tutorial with Evan Coury introduced ZF2's MVC including the foundation concepts of service manager and event manager. We also looked at routing, bootstrapping, controllers and views.

De Montfort University 2013: Introduction to ZF2

Zend Framework 2 has matured nicely over the last 6 months, so this talk looked at how it works! In this talk, I walked through the structure of a ZF 2 application. I covered configuration, service location, modules, events, and the MVC system to provide a clear introduction to the key elements of a Zend Framework 2 application.

Investigating Apigility

At ZendCon 2013, Zend announced Apigility which is intended to ease the creation of APIs. It consists of these things: A set of ZF2 modules that do the heavy lifting of creating an API A application wrapper for creating standalone web API applications A built-in administration website for use in development to define the API Rather nicely, it supports REST and RPC and deal with error handling, versioning & content negotiation for you. Getting started… continue reading.