(Disclaimer: I just started learning cakePHP, sorry if my language isn’t too descriptive)
I have two tables: One is for users, the other is for employers.
Each user contains a employer id, belonging to a unique employer.
When a user goes to the path I’m concerned about, I need to load every user, and for each of those users the name of the employer they work for. How can I go about this? (even hints are greatly appreciated)
What I’ve tried so far:
//run queries here
$this->loadComponent('Paginator');
$users = TableRegistry::get('Users')->find('all');
foreach($users as $user){
$employer = TableRegistry::get('Employers')->find()->where(['id' => $user->employer_id]);
$user['employer'] = $employer->name;
}
$this->set('data', $users);