Prev | Current Page 65 | Next

Rob Allen, Nick Lo, and Steven Brown

"Zend Framework in Action"


As Zend_Db_Table implements the Table Data Gateway design pattern, it provides a number of functions
for collecting data including find(), fetchRow() and fetchAll(). The find() function is used to find rows by
primary key and the fetch methods are used to find rows using other criteria. The only difference between
fetchRow() and fetchAll() is that fetchRow() returns a single rowset, whereas fetchAll() returns an array of
rowsets. Zend_Db_Table also has helper functions for inserting, updating, and deleting rows with the functions
insert(), update() and delete() respectively.
Whilst Zend_Db_Table is interesting in its own right, its usefulness comes out when we add business logic
to it. This is the point when we enter the realm of the Model within MVC. There are lots of things you can do
and we??™ll start with overriding insert and update for our News model.
First of all, let??™s assume that our news database table has the following definition (in MySQL):
CREATE TABLE `news` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`date_created` DATETIME NOT NULL ,
`date_updated` DATETIME NULL ,
`title` VARCHAR(100) NULL ,
`body` MEDIUMTEXT NOT NULL
)
To make our News class, a model, the first business logic that we will implement is to automatically
manage the date_created and date_updated fields when inserting and updating records as shown in listing 2.


Pages:
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
hotele londyn botox Kraków Okna PCV Wrocław basketball.sport24x7.net projektowanie ogrodów łódź