Skip to content

Instantly share code, notes, and snippets.

@dantman
Created July 15, 2012 05:38
Show Gist options
  • Save dantman/3115181 to your computer and use it in GitHub Desktop.
Save dantman/3115181 to your computer and use it in GitHub Desktop.
Closure based result iterator
<?php
class Application {
// [...]
function getOwners() {
$res = $db->select(
array( 'user', 'application_owner' ),
User::selectFields(),
array( 'ao_app' => $this->getID() ),
__METHOD__,
null,
array( 'application_owner' => array( 'LEFT JOIN', 'user_id=ap_user' ) )
);
return new DatabaseResultIterator( $res, function( $row ) {
return User::newFromRow( $row )
} );
}
// [...]
}
// [...]
foreach ( $app->getOwners() as $user ) {
// [output row]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment