2010-02-10 4 views
0
Select * from tableName order by id desc limit 10 

데모를 통해 교리와 같은 것을 수행하는 방법은 무엇입니까?교리에 관한 새내기 질문

function getResults() 
{ 
    $results = self::createQuery("q") 
    ->select("q.*") 
    ->orderBy("q.id DESC") 
    ->limit(10) 
    ->execute(); 

    return $results; 
} 

가 당신에게 결과의 교리 수집합니다 : 모델의 표 클래스 (예를 들어 tableNameTable.class.php) 내부

답변

0

대부분의 사람들은 특정 테이블 클래스를 작성하지 않지만 CLI 툴을 통해 자동 생성 된 Doctrine_Record 클래스를 사용합니다. 즉, 귀하의 경우 만약 당신이 항상 ID의 DESC 모든 결과를 주문하고 10 모든 쿼리를 제한하는 것을 발견하면

, 당신은

//instantiate your record class 
$model = new TableName(); 

$model->getTable() //returns an instance of Doctrine_Table for current Doctrine_Record 
     ->createQuery() //returns a Doctrine_Query instance with the current table loaded 
     ->orderBy("id DESC") 
     ->limit(10) 
     ->execute(); 

과 같은 작업을 수행 할 수 있습니다, 당신은 또한 교리에 후크를 추가 할 수 있습니다 좋아요 기록 수업

class TableName extends Base_TableName //most Doctrine Records extend a base record with config info 
{ 
    //this hook will order all by id and limit all queries to 10 
    public function preDqlSelect(Doctrine_Event $event) 
    { 
     $event->getQuery() 
      ->addOrderBy("id DESC") 
      ->limit(10); 
    } 

}