Im not sure what the reqs of a VO for AMF are but Zend_Table does do what
youre describing essentially.

The thing is Zend_Db_Table returns a Zend_Db_Table_Rowset from the fetch
methods. which is what you are actually calling getAll() on. However getAll
doesnt actuall have instantiated VO's yet until AFTER you iterate through
the rows (or seek to a specific row - then i beleive it only instantiates
that VO). Im sure this was done to make huge result sets manageable...

Secondly if you look at the Zend_Db_Table_Rowset class' current() method
youll see that unless you also implement your own rowset class your VO
constructor is expecting the wrong data structure... youve set it up to be
excpeting the row data as an array when actually its expceting an array
containing the table class instance||string name, the array of data, a
property called stored and a property called readOnly.





sideDoor wrote:
> 
> Greetings,
> 
> I've been using and I'm fairly clear on serialization between AS3 (both
> Flex and Flash) and PHP via Zendamf.  However, in effort to save
> developmental time, I'm interested in leveraging mapping between an SQL
> query result and Zend via the protected $_rowClass property of a concrete
> Zend_Db_Table_Abstract object.
> 
> It seems to me this should be a no-brainer:  I thought I could set the
> $_rowClass property of the Zend_Db_Table_Abstract object to return SQL
> result-rows mapped to a Value Object (VO) of my design, and I figured that
> that the database fields returned from a query would be mapped to public
> properties on the VO object assigned in the $_rowClass property, but I
> couldn't get this to work, not like I thought it would be implemented -
> instead, and empty VO object was instatiated, along with a mixed-array
> containing the data return from the db.
> 
> I've been using 3 PHP objects in this process
> 
> 1. Data-Access-Object, which contains public methods called from AS3/Flex
> and which HAS-A Zend_Db_Table_Abstract object
> 2. The Zend_Db_Table_Abstract object itself
> 3. A Value Object to hold data to be mapped between AS3/Flex and Zendamf
> 
> To get around this, the only solution I could find was to iterate the
> resulting rowset and instantiate a VO per row, so note the getAll() method
> below in the ProjectDAO class:
> 
> 
> // 1. DATA-ACCESS-OBJECT
> [code]<?php
> final class ProjectDAO
> {
>     private $_db;
>     private $_table;
>   
>     public function __construct()
>     {
>         $this->_db         = Zend_Registry::get('db');
>         $this->_table     = new Database_Table_ProjectTBL();
>     }
> 
>     public function getAll()
>     {
>          /* NOTE: I was trying to do this, thinking the
> Zend_Db_Table_Abstract object was going to map the database fields to the
> VO object for me:
>          * $rowset = $this->_table->fetchAll();
>          * return $rowset->toArray();
>          */
>        
>          /* But in the end, this is the best solution I could find, but
> this doesn't seem efficient: */
>          $aReturn = array();
>            
>          $rowset = $this->_table->fetchAll();
>          foreach ($rowset as $row)
>          {
>              $projectVO = new ProjectVO($row->data);
>              array_push($aReturn, $projectVO);
>          }
>          return $aReturn;
> 
>     }[/code]
> 
> 
> // 2. CONCRETE Zend_Db_Table_Abstract object
> [code]<?php
>     class Database_Table_ProjectTBL extends Zend_Db_Table_Abstract
>     {
>         protected $_name = 'project';
>         protected $_primary = 'id_project';
>         protected $_rowClass = 'ProjectVO';
>     }[/code]
> 
> 
> //3. THE VO definition looks like this:
> [code]<?php
>     class ProjectVO
>     {
>         public $id_project = '';
>         public $id_client = '';
>         public $project = '';
>         public $desc = '';
>        
>         function __construct($data = array())
>         {
>             foreach($data as $fieldName=>$value)
>             {
>                 $this->$fieldName = $value;
>             }
>         }
>        
>         public function getName()
>         {
>             return get_class($this);
>         }
>        
>         function __toString()
>         {
>             return $this->getName();
>         }
> 
>     }
> [/code]
> 
> So, so clearly, I'm confused about $_rowClass property and how it should
> be used, and was wondering if you might be able to comment on exactly what
> is the point of the $_rowClass property if mapping to the $_rowClass must
> be done manually via iteration?
> 
> Thanks,
> sd
> 

-- 
View this message in context: 
http://www.nabble.com/Right-way-to-use-%24_rowClass-to-class-map-via-Zend-MySQL--tp25967229p26017190.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to