Snippets

Create an account or login to be able to add, comment and rate snippets.

Navigation

Build queries dynamically...

Example Table static methods for retrieving data. Passing query objects to allow you to modify and reuse existing methods.

static function retrieveUsers($query = null)
{
  if( $query === null )
  {
    $query = new Doctrine_Query();
  }
 
  $query->select('u.*');
  $query->from('User u');
  $users = $query->execute();
 
  return $users;
}
 
static function retrieveUsersWithProfile($query)
{
  if( $query === null )
  {
    $query = new Doctrine_Query();
  }
 
  $query->select('p.*')
  $query->innerJoin('u.UserProfile p');
 
  return UserTable::retrieveUsers($query);
}
 
static function retrieveUserByUsername($username, $query = null)
{
   if( $query === null )
   {
     $query = new Doctrine_Query();
   }
 
   $query->where('u.username = ?', $username);
   $users = UserTable::retrieveUsers($query);
 
   return $users[0];
}
by Jonathan Wage on 2007-04-05, tagged doctrine 
You need to create an account or log in to post a comment or rate this snippet.