Prev | Current Page 64 | Next

Rob Allen, Nick Lo, and Steven Brown

"Zend Framework in Action"

Zend_Db_Table uses Zend_Db behind
the scenes and provides a static class function, setDefaultAdpater() for setting the database adapter to be used
for all instances of Zend_Db_Table.
$db = Zend_Db::factory('PDO_MYSQL', $params);
Zend_Db_Table::setDefaultAdapter($db);
We don??™t actually use Zend_Db_Table directly. Instead, we create a child class that represents the
database table we wish to work with. For the purposes of this discussion, we will assume that we have a
database table called ???news??? with the columns id, date_created, created_by, title, and body to work with. We
now create a class called News:
Class News extends Zend_Db_Table
{
protected $_name = 'news';
}
The $_name property is used to specify the name of the table. If it is not provided then Zend_Db_Table
will use the name of the class and is case-sensitive. Zend_Db_Table also expects a primary key called id
(which is preferably automatically incremented on an insert).Both these default expectations can be changed
by initializing the protected member variables $_name and $_primary respectively. For example:
class LatestNews extends Zend_Db_Table
{
protected $_name = 'news';
protected $_primary = 'article_id';
}
The LatestNews class usese a table called ???news??? which has primary key called ???article_id???.


Pages:
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
stolarka aluminiowa częstochowa Potopek uchwyt lcd wyciągarki hotele londyn