A free and open-source book on ZF3 for beginners


4.19. Models

A model is a PHP class which contains the business logic of your application. The business logic is the "core" of your website. It implements the goal of site operation. For example, if you implement an E-commerce website, you will have models implementing the product catalog and the shopping cart.

In general, the term model means a simplified representation of a real-life object or phenomenon. Simplified because the real-life object has infinite amount of properties. For example, a real-life person who visits your site consists of billions of atoms, and you cannot describe them all. Instead, you take several properties of the object, which are the most important for your system and ignore all others. For example, the most important properties of the site visitor (from website architect's point of view) are first name, last name, country, city, post code and street address.

Models can have some behavior. For example, a mailer model may send E-mail messages, the currency converter model may be able to convert money and so on.

With ZF3, you represent models as usual PHP classes. Properties are implemented as class fields, and the behaviors are implemented as class methods.


Top