Pragmatism in the real world

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.

Pádraic Brady: A Hitchhiker’s Guide to Cross-Site Scripting (XSS) in PHP (Part 1)

Pádraic Brady has posted A Hitchhiker’s Guide to Cross-Site Scripting (XSS) in PHP (Part 1): How Not To Use Htmlspecialchars() For Output Escaping: Always set the third parameter to htmlspecialchars(), set it correctly, and make sure your document is never served with a mismatched or invalid character encoding! Don’t expect some theoretically perfect world to magically appear – browsers are filthily efficient at doing weird things you don’t expect. With a nod to the anniversary… continue reading.

Some Zend\View examples

With the release of Beta 3 of Zend Framework, we now have a significantly refactored the ZendView component. One of the changes made is that there is a ViewModel object that is returned from a controller which contains the variables to be used within the view script along with meta information such as the view script to render. The really nice thing about ViewModels is that they can be nested and this is how the… continue reading.

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.

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.