Controller Testing with the FlashMessenger in Zend Framework

During a recent project, I encountered problems with the flash messenger not playing ball with PHPUnit. The problem, the FlashMessenger using a session namespace, and trying to start the session.

Additionally to this problem, how do you test that the flash message is set as you’d expect (or not as the case may be)

The answer to both of these problems, lies in the same solution. a Mock Object.
Read the rest of this entry »



Using Twig with Zend Framework

Twig, in short, is a templating system for PHP. But PHP is already a templating system many would argue! Well, I wouldn’t argue against that point. However, with the recent excitement in the air in the PHP Community about Symfony 2, I thought it worth checking out.
Mostly I thought they were silly things that were not really needed unless you had a team of designers to work with, however, during my exploration, a couple of things occurred to me that I had not considered about templating systems before. One being the enforced separation of concerns they provide; you simply cannot do anything from inside them which you shouldn’t be, keeping your presentation very very clean. The second, being that they’re not all as terrible as Smarty.

Read the rest of this entry »

, , , ,



Back in October 2010, I was amazingly lucky, and won a ticket to the PHPBenelux 2011 conference! stuff like that doesn’t often happen to me, infact, phpnw is one of the few places I’ve ever won anything, the previous year I won a copy of PHP Object Oriented Solutions.

With much excitement, I arranged to travel with Rob Allen to the conference, as we are in (relatively) close proximity, and traveling with someone is always better than traveling alone.

As the months quickly passed by, the conference schedule was soon posted, and I became immediately impressed with the lineup, with speakers from America making an appearance along with the big names in PHP from Europe, this was going to be a great conference.

Read the rest of this entry »


Zend Framework tips on Evernote

I have started compiling a notebook of tips and answers to commonly asked questions to Zend Framework questions, and common patterns of Zend Framework application design.

Im kicking it off with two notes, one for modules setup, and the other for how to route your requests so that you can divide your controllers up further with subfolders (no hacking required!)

Checkout the notebook now on Evernote

I will keep adding to this as often as possible, and will post updates here with links to new notes

1 Comment

Speaking at the first ever PHP South West

Ryan gives the first PHPSW talkLast Wednesday (1st September 2010) I had the privilege of giving the first ever talk at PHPSW, a new PHPUG for developers in the South West, and Wales. PHPSW has been put together kindly by Stuart Herbert, a great guy who I have had the pleasure of meeting briefly at past conferences and seeing give his talks on Twittex and Living With Frameworks.

Our venue for the evening was Bush House, a nice place with perfectly sized meeting rooms for the 15 guys who attended.

The talk I gave, was a rehersal for my talk at PHPNW10, which is entitled ‘Zend Framework: Getting to grips‘, and is aimed at  developers who have made it past the first steps of Zend Framework, and are moving on into the realms of developing their understanding, and exploring the quirks and nuances.

The audience!

My talk went down well (at-least, nobody fell asleep), besides a few mistakes on my part when putting my slides together, and gave me some valuable experience to ensure that things go smoothly at PHPNW10, and a huge thanks has to be said to everyone there once more for all the feedback, you’ve given me a much needed confidence boost!

Afterwards, it was time to head downstairs to Arnolfini‎, where we all got to mingle and socialise, and discuss all things geeky and wonderful, which is quite a refreshing experience having only experienced such pleasures when attending conferences.

It was also a pleasure to see a few guys who I have encountered over time on IRC, and also to see and appearance from Rob Allen, author of Zend Framework in Action, whom I have come to regard as a friend over the years from both IRC and bumping into at conferences over the last few years, and was kind enough to give me permission to use the pics he took for this post. Another pleasant surprise was the presence of Marcus Degalos, who will be hosting the framework shootout at PHPNW10, and is a Bristol resident, so hopefully we can expect to see much more of him at future meetings.

If you’re in the south west or wales, and you’re a php developer, come and sign up to the mailing list, and get yourself along to the next meeting. See you there! The next scheduled PHPSW meeting will be on Wednesday 13th October 2010 (Venue TBA), so we can pick apart and share our experiences of PHPNW10!

(Before anyone asks to see the slides, they will be available after PHPNW10)

, ,

1 Comment

Keeping your HTML valid with Zend Framework, Tidy and Firebug

With Zend Framework there is an easy way to ensure that you always create valid HTML in your applications. This involves the use of a simple Front Controller Plugin, and the php Tidy component.

Valid HTML is important for a great many reasons, the most important of which is ensuring consistency across all of your visitors browsers. The first step to making sure that your site appears correctly on all the browsers is to ensure that your HTML is valid. Even if the goons at Microsoft continue to ignore the standards and do their own thing, if you at least ensure your html passes validation, then fixing things for Internet Explo(r|it)er of all its versions is a far easier task, and usually possible with a few simple extra styling rules in your CSS.
Read the rest of this entry »


Massive zend framework poster \ cheatsheet

The other day, a wonderful thing arrived in the post, fresh from Björn Schotte of mayflower.

The poster covers many of the commonly used components, and their parameters. I have had it on the wall for about 2 weeks now, and it has become something of a crutch already, and makes it very handy to quickly check, for example whether it’s dispatchLoopShutdown or dispatchLoopShutDown in a FC plugin, or what the parameters for the headLink helper are (two things I always have to double check!)

Mayflower is a partner of Zend, and offers many training and consulting services for PHP companies, as well as developing their own software solutions, such as the “Chorizo!” security auditing suite, and consulting for the popular lightweight webserver “lighttpd”.

Check out the mayflower site at, and drop Björn Schotte an email if you are interested in a poster of your own, he may have some left!


Creating simple, extendible CRUD, using Zend Framework

The Form

Creating a nice, easy to maintain form, starts with a form class. Creating your forms procedurally in your controller/actions is horrid. please don’t do it.

To start with creating your form classes, you need your own namespace in your library. If you don’t have this, register one. This can be done by adding an _initAutoloading method to your Bootstrap. below is a short example. its not comprehensive (you can also do this in your ini i believe, but I use php configuration files similar to DASPRiD‘s, and i’m not trying to show how to set up autoloading here.) Read the rest of this entry »


Zend Framework 1.8 is upon us!

Thats right, 1.8 is here!

And with it comes with a whole bag load of new features, 4 of which i’m very eager to get using, in Zend_Application, and Zend_Tag, and Zend_Tool, and Zend_Navigation. There is another component which interests me, which is of course Zend_Validate_Db_RecordExists and Zend_Validate_Db_NoRecordExists, which were my small contribution to this release.

Read the rest of this entry »


Why the Zend Framework Actionstack is Evil

The action stack seems to be a useful component to some people when starting out with the Zend Framework. This component is a seemingly un-needed part of the framework, as there really is no use-case for it which cannot be simplified with the use of a partial view, which reads data directly from the model, possibly with a view helper alongside to provide some additional logic function, such as deciding on which view partial to use.

This part of the Framework causes the dispatch to loop. This is a costly process, as it involves quite alot. It also adds some further issues to your application design, such as where you should put code. for example if you have some code in your predispatch, and your looping through two actions in that controller, that code will be run twice. This is obviously, not good, and quite un-needed. Further complications can be added when it comes time to add ACL or authentication.

Read the rest of this entry »

, , , , ,