php and Users.php for the two classes as it makes the application easier to
maintain.
Listing 5.7: Creating a Model using Zend_Db_Table compoents
class Users extends Zend_Db_Table_Abstract
{
protected $_name = 'users';
protected $_rowClass = 'User'; #1
}
class User extends Zend_Db_Table_Row_Abstract
{
}
(annotation) <#1. Link the User class as the class to use when creating Rows for this table.>
Linking the User class to the Users class is done through the property $_rowClass in the Users table. This
means that the Zend_Db_Table_Abstract class will create objects of type User whenever it would normally
have created an object of type Zend_Db_Table_Row. The implementation in listing 5.6 is not very useful over
and over the standard Zend_Db_Table_Row though as no additional functionality is provided. To make our
User class useful, we are going to add a new property called ???name???. This will be used throughout the
application to display the user??™s name. It will initially display the combination of first name and surname, but
if they are not set, then it will use the user??™s username.
Our initial implementation of the function User::name() is therefore:
Class User extends Zend_Db_Table_Row_Abstract
{
public function name()
{
$name = trim($this->first_name .
Pages:
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166