Book Image

PHP Web Development with Laminas

By : Flávio Gomes da Silva Lisboa
4.5 (2)
Book Image

PHP Web Development with Laminas

4.5 (2)
By: Flávio Gomes da Silva Lisboa

Overview of this book

Considered the next generation of the Zend framework, Laminas is a high-performance PHP framework for creating powerful web applications with an evolutive architecture. This book takes a hands-on approach to equip you with the knowledge of the Laminas framework necessary to start building web applications based on the reuse of loosely coupled components. You'll learn how to create the basic structure of a PHP web application divided into layers, understand Laminas’ MVC components, and be able to take advantage of the Eclipse platform as a method for developing with Laminas. Step by step, you'll build an e-commerce application based on the technical requirements of a fictional business, and get to grips with implementing those requirements using Laminas components. By the end of this web development book, you’ll be able to build a completely secured MVC application in PHP language using Laminas.
Table of Contents (20 chapters)
1
Part 1: Technical Background
6
Part 2: Creating an E-Commerce Application
13
Part 3: Review and Refactoring

Creating mapped models

This is a useful tip for avoiding headaches when you are creating models mapped to tables with laminas-db. These models need to implement two methods, that is, exchangeArray and getArrayCopy:

public function exchangeArray($data)

The exchangeArray method is used by the Laminas\Db\ResultSet class to populate a model with data from a table record.

public function getArrayCopy()

The getArrayCopy method is used by the Laminas\Db\ResultSet class to get data from a model. It is also used by Laminas\Form\Form to bind model attribute values to form field values.

In fact, the Laminas\Db\ResultSet class also accepts a toArray method, replacing the getArrayCopy method. I suggest implementing the toArray method in models to extract the data to be persisted with the TableGateway class. Sometimes, the model data to be sent to a form object is different from the model data to be sent to a data mapper. You can show, in an HTML form, data that won’t be saved...