2012-01-25 112 views
1

我必須按玩家Id返回該行,如果沒有行,則創建一個。 這不能是最好的辦法。在Symfony 1.4中使用Propel

class PlayerRafPeer extends BasePlayerRafPeer { 

    /** 
    * Returns a PlayerRaf object by playerId. 
    * @param int $player_id 
    * @param PDO $con 
    * @return PlayerRaf 
    */ 
    public static function retrieveByPlayerId($player_id, $con = null) 
    { 
    if ($con === null) { 
     $con = Propel::getConnection(self::DATABASE_NAME); 
    } 

    $criteria = new Criteria(); 
    $criteria->add(self::PLAYER_ID, $player_id); 
    $v = self::doSelectOne($criteria, $con); 

    if (!$v) { 
     $player = new PlayerRaf(); 
     $player->setPlayerId($player_id) 
      ->setEmailCount(0) 
      ->setDate(date("Y-m-d"), time()); 
     self::doInsert($player, $con); 
     return $player; 
    } 
    return $v; 
    } 

回答

相關問題