$this->loadModel('Users');
$this->loadModel('Admins');
This two tables have same column
$users = $this->Users->find('all')->toArray();
$admins = $this->Admins->find('all')->toArray();
$all_data = array_merge($users,$admins);
Get data as array and merge both array to get combined data
usort($all_data , function($a, $b) {
return $a['created_on'] <=> $b['created_on'];
}); //need php7+ for work
using this to sort data on created_on
Merge Data..
[
{
"id": 1,
"name": "xxx",
"email": "xxx@xxx.xx",
"created_on": "2020-10-06T00:00:00"
},
{
"id": 2,
"name": "yyy",
"email": "yyy@yyy.yyy",
"created_on": "2020-10-07T00:00:00"
},
{
"id": 3,
"name": "xxx1",
"email": "xxx1@xxx.xx",
"created_on": "2020-10-06T00:00:00"
},
{
"id": 4,
"name": "yyy1",
"email": "yyy1@yyy.yyy",
"created_on": "2020-10-08T00:00:00"
},
{
"id": 1,
"name": "zzz",
"email": "zzz@zzz.zzz",
"created_on": "2020-10-06T00:00:00"
},
{
"id": 2,
"name": "aaa",
"email": "aaa@aaa.aaa",
"created_on": "2020-10-15T00:00:00"
}
]
Merge Data - After sort
[
{
"id": 1,
"name": "xxx",
"email": "xxx@xxx.xx",
"created_on": "2020-10-06T00:00:00"
},
{
"id": 3,
"name": "xxx1",
"email": "xxx1@xxx.xx",
"created_on": "2020-10-06T00:00:00"
},
{
"id": 1,
"name": "zzz",
"email": "zzz@zzz.zzz",
"created_on": "2020-10-06T00:00:00"
},
{
"id": 2,
"name": "yyy",
"email": "yyy@yyy.yyy",
"created_on": "2020-10-07T00:00:00"
},
{
"id": 4,
"name": "yyy1",
"email": "yyy1@yyy.yyy",
"created_on": "2020-10-08T00:00:00"
},
{
"id": 2,
"name": "aaa",
"email": "aaa@aaa.aaa",
"created_on": "2020-10-15T00:00:00"
}
]