Building ZF3 composed pages using Nesting View Models and Forward Controller Plugin

Normally in ZF3 MVC projects, each controller action matches one view and use it to render its output.

Occasionally, we may want to build your ZF3 pages by dispatching various controllers from within the matched controller and merging outputs into a unique final view. In this way we can aggregate one or more views to create complex pages like report summaries or widget dashboards.

In this post, we will see how to write few lines of code to include output of an arbitrary action into action matched from route.

Continue Reading

How to inject Zend Service Manager in ZF3 Controllers

Zend Service Manager component is Zend Framework’s implementation of service locator pattern. This object is very usefull component for an application and is largely used in ZF applications.

Unfortunately in ZF3 default application, Service Manager component is no more available in controllers.

An official solution exsists for this, but in this little tutorial, I want to share an easy solution to inject Service Manager in all controllers.

Continue Reading

How to setup a Translate Controller Plugin in Zend Framework 3

Sometimes in our Zend Framework 3 multi-language application, we could need to access to Zend Translator component directly from Controllers. For example, when we have to translate a string to return in a JsonModel.

So, let’s see how to write a very simple Controller Plugin that will help us to save a lot of code (and time).

Following explanation will assume we just have at least a Skeleton ZF3 Application with working Zend Translator component.

Continue Reading

Update Twitter Bootstrap to release 3 in Zend Framework 2

Recently I started a new project based on Zend Framework 2, using Twitter Bootstrap as CSS framework. Some days ago, new Bootstrap v3 was released and introduced a lot of changes and improvements. Because of ZF2 Skeleton Application comes out-of-box with Twitter Bootstap 2, I decided to setup the new project skeleton and update CSS framework to latest available release.

In this post, I’ll describe the process to update Bootstrap to v3 into a ZF2 project.

Please note: I set up the project with Zend Framework 2.2.2 and updated to Twitter Bootstrap 3.0.0-rc1 because, actually, are latest available versions. If time is passed, you should check official documentations to ensure that this procedure is still valid.

I’ll describe update process assuming that we have a working Skeleton Application deployed following Zend Framework Getting starded guide.

First of all, we have to update libraries in public/ folder by accomplish following steps:

  1. Download Twitter Bootstrap library package and unzip it.
  2. Move content of dist/ folder into <project>/public/ folder.
  3. Download Glyphicons package and unzip it.
  4. Copy fonts/ folder into <project>/public/ folder.
  5. Copy css/bootstrap-glyphicons.css into <project>/public/css/ folder.
Continue Reading

Setup Doctrine 2 filters in Zend Framework 2

Scenario

Doctrine filter is a very powerfull tool that can be used to add conditional clauses at SQL level into our Doctrine 2 engine. This means that filters constraints will affect DQL queries, collections, lazy loading, etc.

How to setup and use filters in generic conditions is well explained in this article of official Doctrine documentation, but in a Zend Framework 2 project, the same operation is a bit different.

So, in this post, we will explain how to configure one or more filters into our Zend Framework 2 projects.

Continue Reading