Having recently learned the ZF framework, the introduction to the Section Zend_db_table_row in the Handbook, "Zend_db_table::find () or:: FindRow () method can return a Zend_db_table_row object, The object is automatically mapped to this row of records in the table, fields and class properties are fully associative (field names are underlined, property names are named by the first lowercase camel, such as automatic "last_name", the property name "LastName" is manipulated), and any field is directly like the Action class property Such as:
$row = $table->fetchrow (' first_name = "Robin");//$table is a zend_db_table instance
echo $row->lastname;//assume output ' Bill '
And the modified operation is super convenient, directly to the property assigned to the Save () method can be called, such as:
$row->lastname = ' Gates '; $row->save ();
The data is automatically updated to the table. After a deep dive into the next source, roughly or logically a bit more, so their own rationale, here put a simple integration of the idea of the class, according to the data object mapping mode to think, can help to understand.
<?php/** * Data Object mapping mode *class datamapping{protected $id; protected $data; protected $db; protected $change = false; function __construct ($id) {$this->db = Factory::getdatabase (); $res = $this->db->query ("select * from user where id = $id limit 1"); $this->data = $res->fetch_assoc (); $this->id = $id; } function __get ($key)//Implement object manipulation properties to manipulate the table field value {if (Isset ($this->data[$key])) {return $t his->data[$key]; }} function __set ($key, $value)//For the new field can be updated directly into the data table {$this->data[$key] = $value; $this->change = true; } function __destruct ()//destructor implementation Save () logic {if ($this->change) {foreach ($this->da Ta as $k + $v) {$fields [] = "$k = ' {$v} '"; } $this->db->query ("Update user set".) Implode (', ', $fields). "Where id = {$this->id} limit 1"); } }}
Reflection on data Object Mapping mode of ZF framework