2010-02-10 79 views

回答

2

内部模型的表类(如tableNameTable.class.php):

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

    return $results; 
} 

会给你结果的学说集合。

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); 
    } 

}