Hello nerVo,

I'm not sure I understand what you mean, but I think Zend_Db_Table is the thing you should be looking at. Zend_Db_Table is a TableModule for the Zend Framework. It connects to your database via Zend_Db_Adapter, examines a table for its schema, then aids you in manipulating and fetching rows from that table.

I also believe that there's an XML adapter.

Using your sample code you could do:

class News extends Zend_Db_Table
{}

|$news = new News();

$data = array(
   'title' => 'Foo',
   'body'  => 'bar'
)

$id = $news->insert($data);

"Data" is a much too broad subject, which I don't think we should be wrapping in a Zend_Data class ... I'd rather use standard PHP functions for "data handling".

Best regards,


|

--
Andries Seutens
http://andries.systray.be

i18n Locale Team is looking for your help.  Volunteers are always welcome to 
contribute their feedback, bug fixes, suggestions for enhancements and 
improvements, experimental patches, and especially their ideas on the fw-i18n 
mail list.

||
nerVo schreef:
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 ?
Gecontroleerd op virussen door de JOJO Secure Gateway.

Reply via email to