When you define your table class, you can define the protected
$_rowsetClass:
class MyDbTable extends Zend_Db_Table_Row_Abstract
{
$_rowClass = 'MyRowClass'; // each one can be defined without the
second one
$_rowsetClass = 'MyRowsetClass';
}
Mickael
Abraham Block a écrit :
> You can always populate you're row class with the data from the
> returned rowset's toArray() method....
>
> I know its not elegant, but it certainly works!
>
> On Tue, Dec 16, 2008 at 10:26 PM, Dan Wilson <dwilson@acucore.com
> <mailto:dwilson@acucore.com>> wrote:
>
> Yeah, I figured that one out, but I was hoping for something a little
> less hack-ish.
>
> Here's my code (assuming that we don't know the rowClass, but we do
> know the table class [as is my case]):
>
> [code]
> foreach ($results as $result) {
> $tbl = new MyDbTable();
> $rowClass = $tbl->getRowClass();
> $resultObj = new $rowClass(array('data' =>
> get_object_vars($result), 'table' => $tbl));
> }
> [/code]
>
> My $resultObj now has the proper methods attached as well as goes
> through the custom rowClass init (which was the crucial part).
>
> But again, is there an easier way to do this? It would be really nice
> to be able to indicate the rowClass in the select or something.
> Here's a proposal:
>
> [code]
> $select = $db->select()->from( array('p' => 'products', '_row' =>
> 'MyRowClass') );
> [/code]
>
> Then that code can be done behind the scenes. Is there a possibility
> of something like this?
>
> Thanks,
> -=Dan
>
> On Tue, Dec 16, 2008 at 7:18 PM, Tim Nagel <tim@nagel.com.au
> <mailto:tim@nagel.com.au>> wrote:
> > Check out the default rowset class to see where it creates them
> (and you'll
> > be able to do the same thing). I think you'll need to pass in a
> table object
> > with the data.
> >
> >
> > T
> >
> > On Wed, Dec 17, 2008 at 10:13, Dan Wilson <dan@codeality.com
> <mailto:dan@codeality.com>> wrote:
> >>
> >> Is there any way to force a rowClass from outside a Table object?
> >>
> >> I'm doing a select on the adapter because I have several tables
> that
> >> are all pretty similar. I dynamically set the FROM. But doing
> this
> >> doesn't allow me to take advantage of the custom rowClass I've
> setup
> >> for each table.
> >>
> >> Is there a way to force it to return a rowSet? I'm in the
> process of
> >> converting from Doctrine and it was able to handle this
> (through the
> >> DQL).
> >>
> >> Thanks,
> >> -=Dan
> >>
> >
> >
>
>
没有评论:
发表评论