11th May 2012
Evan Coury has posted Module-specific layouts in Zend Framework 2
First, I should point out that the title of this post is a bit of an intentional misnomer. There’s really no such thing as “module-specific” anything in ZF2, so what we’re really talking about is the topmost namespace of the controller being dispatched. So in the case of MyModule\Controller\SomeController, the topmost namespace would be MyModle. In most cases, this will be the name of a given module.
Here’s how you can easily switch the layout (or perform any other arbitrary logic) for a specific module in Zend Framework 2.0 (as of d0b1dbc92)
He shows how easy it is to register an event that is only triggered when an action belonging to the namespace of the current module is dispatched. If you need to change the layout for a given module, this is the best way to do it as of today.
His point that a Module is merely the namespace of the dispatch controller is very important to understand too!
27th April 2012
Evan Coury has posted Sharing a database connection across modules in Zend Framework 2 » Evan's Blog
With the new modular infrastructure in Zend Framework 2, one of the most common questions will indoubitably be how to share a database connection across modules. Here’s a quick explanation of how to share your database connection across multiple modules in a way that can even allow you to use a single connection between Zend\Db, Doctrine2, and possibly even other database libraries / ORMs.
If you're using ZF2, this is a must-read.
15th March 2012
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 case you missed this last Friday, this is an in-depth look at how to construct an object in PHP whilst adhering to SOLID principles. If you missed this last week, read it now! Get a coffee first.
13th March 2012
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 of Douglas Adams' death on Sunday, Pádraic Brady has written possibly the definitive guide to the htmlspecialchars() function.
Read it. Then read it again.
6th March 2012
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 Zend\View, Zend\Db and Zend\Config!