2009年6月18日星期四

Re: [fw-db] Specifying FetchClass custom class in Zend_DB ?

On Thu, Jun 18, 2009 at 12:24 AM, wadearnold<Wade.Arnold@t8design.com> wrote:
>
>
> Is it possible to change the fetch mode of Zend_DB_Adapater to handle
> populating user specified objects like PDO uses? I am writing some tutorials
> for Zend_Amf and the transfer objects are used all the time for sending data
> back forth over the RPC call. When dealing directly with PDO you can specify
> your fetch mode and class name that you want to populate.
>
> $stmt = $pdo -> query('your query');
> $stmt -> setFetchMode(PDO::FETCH_CLASS, 'yourClass', array(0 => false));
> http://php.net/manual/en/pdostatement.setfetchmode.php
>
> The zend db docs "15.1.3.2. Changing the Fetch Mode has Zend_Db::FETCH_OBJ
> and says that the stdclass is used as "default" but it does not say how to
> change it.
>
> I looked at Zend_Db_Adapter_Pdo_Abstract->fetchMode and it only takes one
> argument. Is it possible to use this PDO behavior?
>
> Should I being doing this differently inside of Zend_Db for populating an
> array of VO/DTO transfer objects?

I'm not entirely sure what you want to do, but I think fetchObject()
supports that.

Check this out:
http://framework.zend.com/svn/framework/standard/trunk/library/Zend/Db/Statement.php

The default is stdClass, but you can push in what you want.

Till

没有评论: