在 extbase (TYPO3) 中设置二级数组的 setOrderings

3
我想通过我的TYPO3扩展中的EventRepository函数按日期对“约会”进行排序。
    public function findAll() {

    // Sort appointments ascending
    $query = $this->createQuery();
    Return $query->setOrderings (
        Array('appointments' => Tx_Extbase_Persistence_Query::ORDER_ASCENDING)
    )->execute();

}

我需要获取数组的第二级,例如:'appointments.start_date'。 我的数组看起来像这样:

images => 'originalPreviewJW__2_.jpg' (25 chars)
     categories => Tx_Extbase_Persistence_ObjectStorageprototype object (2 items)
     appointments => Tx_Extbase_Persistence_ObjectStorageprototype object (4 items)
        000000006052eef7000000009b41588e => Tx_SzEvents_Domain_Model_Appointmentprototypepersistent entity (uid=3, pid=13)
              titel => 'entertainment area' (18 chars)
              startDate => DateTimeprototype object (2013-08-22T10:00:00+02:00, 1377158400)
              endDate => DateTimeprototype object (2013-08-22T20:00:00+02:00, 1377194400)

1个回答

6

这应该可以工作

public function findAll() {
    // Sort appointments ascending
    $query = $this->createQuery();
    return $query->setOrderings (
        Array('appointments.startDate' => Tx_Extbase_Persistence_Query::ORDER_ASCENDING)
    )->execute();
}

7
太好了!非常重要的一点是,参考列被称为“appointments.startDate”,尽管表字段名实际上是“start_date”!还有一点需要注意:在ExtBase中,排序方向常量的表示方式已从“Tx_Extbase_Persistence_Query::ORDER_ASCENDING”更改为“\TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING”。 - Jpsy

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接