Kar*_*hik 2 php typo3 typo3-extensions typo3-7.6.x typo3-8.x
我是这样写的
/**
* itemRepository
*
* @var \KRT\KrtEmployee\Domain\Repository\ItemRepository
* @inject
*/
protected $itemRepository = null;
/**
* action list
*
* @return void
*/
public function listAction()
{
$arguments =$this->request->getArguments();
$employees = $this->itemRepository->findAll();
$this->view->assign('employees',$employees);
}
Run Code Online (Sandbox Code Playgroud)
在我的$employees结果中,我有
现在,我怎样才能在排序结果数组升序基于订单
是否有任何默认功能可以在存储库查询中进行排序?
每个存储库都有一个$defaultOrderings属性,您可以在其中指定应用于所有查询方法的默认排序。在您的情况下,它可能如下所示:
protected $defaultOrderings = [
'name' => QueryInterface::ORDER_ASCENDING,
'department.name' => QueryInterface::ORDER_ASCENDING,
'salary' => QueryInterface::ORDER_ASCENDING,
];
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,department.name您还可以按关系的属性进行排序。请注意,这仅适用于 1:1 和 n:1 关系。
如果您的存储库中有自定义查询方法,您可以直接在查询上手动设置排序:
$query->setOrderings([
'name' => QueryInterface::ORDER_ASCENDING,
'department.name' => QueryInterface::ORDER_ASCENDING,
'salary' => QueryInterface::ORDER_ASCENDING,
]);
Run Code Online (Sandbox Code Playgroud)