Pragmatism in the real world

Module specific bootstrapping in ZF2

Update As of Beta 4, this method no longer works. Evan Coury's post on Module-specific layouts in Zend Framework 2 is the correct way to do this. Following on from the discussion on modules, we can hook into the event system to do module specific bootstrapping. By this, I mean, if you have some code that you want to run only if the action to be called is within this module, you can hook into… continue reading.

Modules in ZF2

A Zend Framework 2 application is made up of a number of modules which each contain the controllers, models, views and other support code required to implement a specific part of the application. Within a standard ZF2 application, modules live in one of two places: /module – for application specific modules /vendor – for 3rd party modules It follows that you are not expected to ever modify 3rd party modules that are stored in /vendor.… continue reading.

An introduction to Zend\Di

Zend Framework 2 provides its own dependency injection container, Zend\Di which is a key underpinning of the entire framework and especially the MVC system. I have covered before, my thoughts on the reasons for using dependency injection, so this article looks at the fundamentals of using Zend\Di. Constructor injection Consider this code: namespace My; class DatabaseAdapter { } class UserTable { protected $db; public function __construct (DatabaseAdapter $db) { $this->db = $db; } } This… continue reading.

Overriding module configuration in ZF2

Let's say that you install the ZF-Common's User module. By default, it sets up its routes under the /user path segment like this: vendor/ZfcUser/config/module.config.php return array( // lots of config stuff here /** * Routes */ 'ZendMvcRouterRouteStack' => array( 'parameters' => array( 'routes' => array( 'zfcuser' => array( 'type' => 'Literal', 'priority' => 1000, 'options' => array( 'route' => '/user', 'defaults' => array( 'controller' => 'zfcuser', 'action' => 'index', ), ), 'may_terminate' => true, 'child_routes'… continue reading.

Shahar Evron: Generating ZF Autoloader Classmaps with Phing

Shahar has posted a new article about how to generate ZF2 autoloader classmaps with phing. As the ZF2 classmap autoloader is quicker than the standard autoloader, this can be a benefit in production, so being able to automate the creation is beneficial. Fortunately, using ZF2′s autoloader stack and Phing, we can enjoy both worlds: while in development, standard PSR-0 autoloading is used and the developer can work smoothly without worrying about updating class maps. As… continue reading.

What problem does dependency injection solve?

Zend Framework 2 comes with a dependency injection container (DIC), as does Symfony 2 and Aura, along with many other PHP frameworks that target PHP 5.3 or higher nowadays. This article attempts to explore the problem that a DIC tries to solve. Consider this simple (contrived!) example of an Album object that has an Artist object: class Album { protected $artist; public function getArtistName() { return $artist->getName(); } } The question is how to we… continue reading.

Using Zend\Loader\Autoloader

Autoloading is the process in PHP whereby the system attempts to load a class when it is first encountered (via new or via class_exists) if it hasn't already been loaded via a require or include. Autoload works by looking for a method called __autoload or walking through any method registered with spl_autoload_register. Zend Framework 2 provides the Zend\Loader\Autoloader component for autoloading of Zend Framework and your own classes. What does it provide? The ZF2 autoloader… continue reading.

Zend Framework 2 Beta 2 released

Zend Framework 2, Beta 2 has been released! The key new features are: Refactored Mail component Refactored Cache component MVC updates Check out Matthew's blog post for the full details. I've also updated my tutorial. This is a good time to get involved, try it out and let us know what you like/dislike.

ZF2 no longer requires a CLA to contribute

In #zf2 news, effective immediately, we no longer require a CLA for #zf2 contributions. Let the pull requests flow! – @weierophinney Matthew Weir O'Phinney has announced that contributors to Zend Framework 2 do not need to have signed Zend's Contributor License Agreement from now on. Zend Framework 2 is developed using git and there's a mirror on github, this means that contribution to ZF2 is now just a pull request away!

Updated tutorial for Zend Framework 2 beta 1

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!