I do that by combining all the different models into one array and doing Set::sort on that, like this:$allEntities = array();$articles = $this->Article->find( ... );foreach ($articles as $k => $v) { $allEntities[] = $v['Article'];}$documents = $this->Document->find( ... );foreach ($documents as $k => $v) { $allEntities[] = $v['Document'];}$videos = $this->Video->find( ... );foreach ($videos as $k => $v) { $allEntities[] = $v['Video'];}if (sizeof($allEntities) > 1) { $allEntities = Set::sort($allEntities, '/created', 'DESC');}如果您需要实体的模型名称,您可以这样做,例如:If you need to have a model name for the entities, you can do that for example like this:$videos = $this->Video->find( ... );foreach ($videos as $k => $v) { $v['Video']['modelName'] = 'Video'; $allEntities[] = $v['Video'];} 这篇关于组合来自多个模型的数据列表并按在 cakephp 中创建的日期对它们进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
11-03 08:03