Models are a great way of providing functionality to our application, and they keep out the Controllers, nice and clean, from any critical logic. A hydrator is also great to transport properties and values from one model to another, that's why we will go into this a bit further to make optimal use of it.
For this recipe a working Zend Framework 2 skeleton application is necessary to make full use of the examples.
In this recipe we will set up a model and a method for hydrating data to and from our model, so that we have easy access of our data.
We can access the model anywhere in the application by simply adding a use statement at the top of our document:
use Application\Model\SampleModel; $object = new SampleModel();
Or by using the fully qualified name of the class including the namespace, shown as follows:
$object = new \Application\Model\SampleModel();
If there is already a class SampleModel
used, but from a different namespace...