Pragmatism in the real world

Matthew Weier OPhinney: View Layers, Database Abstraction, Configuration, Oh, My!

Matthew Weier OPhinney has posted View Layers, Database Abstraction, Configuration, Oh, My! Late last week, the Zend Framework community 2.0.0beta3, the latest iteration of the v2 framework. What have we been busy doing the last couple months? In a nutshell, getting dirty with view layers, database abstraction, and configuration. This is a must read article if you want to know what's new in ZendView, ZendDb and ZendConfig!

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.

Sublime Text 2 Plugin: Function Name Display

As I'm using Sublime Text 2 more and more, I thought it would be useful to display the current method name in the status bar. I poked around on the forums and created a plugin from ideas I found in a couple of different threads. This plugin is imaginatively titled Sublime Function Name Display! As I've hooked into the on_selection_modified event handler, I was keen to avoid slowing down the editor too much when you… 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.

A primer on PHP namespaces

I know that there are a lot of posts now about namespaces in PHP 5.3. This is mine which is how I learnt how they work. What are namespaces? From the PHP manual: namespaces are a way of encapsulating items Hardly the most useful of definitions, but it's a starting point! A namespace is a way of grouping code that exists across multiple files without having a naming collision. That is, you can have the… 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.

One-to-many joins with Zend_Db_Table_Select

Let's say that you want to set up a one-to-many relationship between two tables: Artists and Albums because you've refactored my ZF1 tutorial. Let's assume that an artist has many albums. These are the basic table definitions: artists table: id, artist albums table: id, artist_id, title When you list the albums, you obviously want to see the artist name rather than the id, so clearly you use a join! Assuming you're using Zend_Db_Table, the easiest… continue reading.