A basic service
One of the biggest features of Zend Framework 2 is the ServiceManager
, and its influence in the framework can be seen from the initial bootstrap of our application. We don't need a reason to explain why this recipe goes deeper in this topic, do we?
Getting ready
Again a Zend Framework 2 skeleton application should be running to make the full use of our examples in this recipe.
Before we continue let's get the difference between a service and a model. Although the definition of a service is sometimes a judgment call, it can be safely assumed that a service is a class between the controller and the model, which hides all the nasty logic from the controller, for example, checking the authentication or calling a method in a model. Another thing that is different is that the service in our case will be managed by the ServiceManager
, and therefore, can be called from any controller (and other service) in our application.
How to do it…
Services are a great way of making sure our functionality...