Hello,

this morning, i was just thinking about an interesting new ZF concept.
Imagine.
You got a class, let's say "News", which treats news on your website.
Datas for this class may come from everywhere : db, xml, csv, ....
The only requisite is that these datas must be indexed (this way, we can do searches, inserts, deletes, ...)

Let's go for a schema, you'll quickly understand what i mean :

Zend/
   Data.php
   Data/
      Adapter/
         Abstract.php
         Db.php
         Xml.php
         Config.php
         ...

Abstract.php implements common methods like finding, fetching, inserting, updating, deleting, ....
Then, every adapter simply implements an existing (or not) ZF elements :
Db.php -> Zend_Db_Table
Xml.php -> Zend_Xml
Config.php -> Zend_Config
...

The code, now :

$news = Zend_Data::factory( $adapter, $config );

or

class News
{
   protected $_data;

   public function __construct($adapter, $config)
   {
      $this->_data = Zend_Data::factory( $adapter, $config );
   }
}

or ...

Three (surely more ) greats aspects of this approach :

1) Totally abstracted and centralized data manipulation
2) We can connect Zend_Data directly to Zend_Form to make all ready forms for one or more elements. 3) We can implement a Zend_Datagrid, which take a Zend_Data object for source (and render it through Zend_Html_Table, or Zend_Pdf, or Zend_Excel, ...)

It sounds good, no ?

Reply via email to