Model is usually comprised of a static class (methods of which are called statically), and several classes that emulate data entities. Calls to the methods of this Model class either return instances of other model classes, or PDOStatement
instances that return instances of model classes in calls to the fetch()
method.
For our application, the classes will be Model, Book, Author
, and Borrower
. These classes reflect the tables in our example database and allow us to perform simple operations on the underlying data. (The main idea is to isolate SQL from the controller scripts into relevant model classes.) For example, the Book
class may have a method to return an Author
class instance that would represent the author for that book. On the other hand, the Author
class might have a method to return a list of Book
class instances representing each book written by that author.
In this chapter, we will develop our own static Model
class along with the Book, Author
, and Borrower...