Skip to content

Zend Framework 2 - Lazy Factory - Kickstarter (for ZF 2.4)

No blabla, just how you do it with zend framework 2.4.

#add following line to your composer.json
"ocramius/proxy-manager": "1.0.*",

composer update

#add following lines to your module.config.php
'lazy_services' => [
    'class_map' => [
        \My\Class::class => \My\Class::class
'service_manager' => [
    'delegators' => [
        \My\Class::class => [
    'factories' => [
        \My\Class::class => \My\ClassFactory::class,
        \Zend\ServiceManager\Proxy\LazyServiceFactory::class => \Zend\ServiceManager\Proxy\LazyServiceFactoryFactory::class

Thats it.

Useful links are a gist from a closed issue and somehow an official howto (maybe working with zend framework greater 2.4).

Translate to de es fr it pt ja

web - Zend Framework 1.12 new autoloader

A quick one today. I found an exciting entry on Robert Basic's Blog called new autoloader in zend framework 1.12.

While i am already working with zend framework 2, i knew about the new autoloading mechanism but its good to know the guys from zend framework are backporting this to the old zend framework 1.

Robert shows you how to use it in your current zend framework 1 projects and links to the zend framework manual and how to increase the classloading performance.

Translate to de es fr it pt ja - the long road to a php data mapper - part 1

I am working on the private project "" to get away from social services and have a tool that fits perfectly to my own requirement. Private projects always (should ;-)) have the benefit of "no time preasure" that leads to "implement some cool features". The first thing on this feature list is a data mapper.

Why a datamapper? Well, won't you like to work with domain models and don't give a s*** about how and where the data is stored? There is a wonderfull and short article created by Martin Fowler and i just have to recomend this one.

I found two datamapper projects for php on the web, pdodatamapper and phpdatamapper. To keep things short, a data mapper removes the logic of "how and where" to store the model data. Both projects are still under heavy development and are not in a final state right now. I will not use them (but always take a look on how they have things done).

So what should my data mapper do? All in all, it should hide all the database tables from the developer - even the orm if used. I just want to create a domain model and use it to store and get data from a persistent storage. My data mapper must be smart enough to figure out which rowset on which storage/database table he has to update (or create). The data mapper should have a lazy loading/storing mechanism, this should be done by a propertieset that knows which propertie is stored on which storage/database table. My data mapper should support a very simple/limited filter mechanism that prevents me to blow up my data mapper class with to many "loadModelWhenItFitsToTheFollowingCircumstances"-methods. This data mapper should also support to create a domain model by the upper called filter mechanism.

I decided that the general data mapper methods "insert()", "update" and "delete" are not perfect in the matter of sense to fit on my requirements. Thats why this data mapper will have the methods "load($model, $filters)", "save($model)" and "delete($model)". You can adapt each data mapper by adding own load methods with pre defined filters.

Filter what? All this filtering leads to a filter class. This is a simple and straight forward one with the properties "criteria", "name" and "value". The filter class has to be independent from the real storage implementation, thats why i will use an aditional filterMapper class.

This filterMapper is used from the data mapper and prevents to write doublicated storage dependent code. He is responsible to transform the general filterset to the a storage dependant model - means you throw the filter and the storage model inside and get the storage model with added storageFilter back. That filter and filterMapper can communicate with each other by using a criteria class. The criteria class will define what "like" or "greater then" is so that the filterMapper can map this to the storage model.

After the trip to the filtering adventure, we are back to the data mapper itself. The real domainModelDataMapper will use a general propertieSet class. This propertieSet class is the only real connection between the domainModelProperties and the (maybe more the one) storage models - so the theorie currently ;-).

I must admit, i have made no decision if the real domainModelDataMapper is a decorator of the dataMapper, or if the dataMapper class is implemented as abstract class. Since the whole project is a "learning by doing", i will figure out what will work - final in the phase of implementation (have i remarked that i never ever have worked with a data mapper for real? ;-) ).

Lets see what is next.

Translate to de es fr it pt ja

tool - Bazzline_Controller_Plugin_Auth - Zend Framework Controller Plugin - now on

I just released my first project on As mention in the headline, it is called Bazzline_Controller_Plugin_Auth. It is a simple plugin which tests if the called url is a "logged in user" only url or not. If it is "logged in only", the user is redirected to the login. The previously called url is saved in the session. After a successfull login, the user gets redirected to this saved url. All can be configured in a config file.

This plugin is only for simple access controll by "user is logged in" or "user is not logged in". The ACL stuff is still in the pipeline and should not - to follow the KISS principle - be inside an auth plugin.

While setting up this project on github, i had some problems while getting a valid connection to github.

I followed the howto but not "pressed enter" when asked for a file to store the key.

Thats why:

ssh -T [email protected]

But when i added the -i option like:

ssh -T [email protected] -i path/to/my/private/key
everything runs smoothly.

After a short term of searching, i found the ssh issues page on The simple solution is:

Create or open the file at ~/.ssh/config Add the following lines:
Host User git Hostname PreferredAuthentications publickey IdentityFile /path/to/my/private/key
After that, the
git push -u origin master
runs without any errors.

Translate to de es fr it pt ja

tool - zend framework zf cli aka zend tool

Just a quick entry for the zend framework comand line tool (available for *nix and windows). I tought it would be a good idea to use it and create the general files or directory layout. But it is not perfect at all. Creating modules and layouts is quick nice. But a

zf create controller myModuleName
does not what i have expected. An controller was created below the general controller directory and not inside the module "myModuleName". Lets see if i like the tool at all. I will stick on it for this project and fill up the links in the following section when i find some usefull one. I can give one hint so far, the zend tool can only create, not delete anything. If you want to delete something, you have to do it manualy (remember the zfproject.xml file).

available parameters for application.ini official zend tool manual using the cli tool create a layout zend tool in phpstorm zend framework as cli application tutorial from akrabat Proposed Q&A site for PHP developers using Zend Framework 1 and Zend Framework 2

Translate to de es fr it pt ja

Building a cms with zend framework

Just by searching for a new technical book i stumbled over Pro Zend Framework Techniques: Build a Full CMS Project.

Well, the price in my local bookdealer was very cheap so i gave him a try. After finishing reading, i must admit that the book touches nearly all sticking points i was falling by learning using the zend framework. The book also shows me more ;-). I like the way the book is written. You begin with easy tasks and refactor the code if needed.

So what you get for your money? 230 Pages full of information. The number of pages guarantees that there is no place for boring stuff. This book presents you straight forward informations about:

  • application.ini
  • Template and Layout
  • Form, FormElement
  • Working with ZendDbTable
  • ZendNavigation
  • ZendAuth
  • ZendAcl
  • ZendSearch
  • Setup Modules
  • The use of DBProfile
  • ZendCache
  • ZendTranslate

If the price fits to your pocket, give him a try :-).

Translate to de es fr it pt ja