Working on my first CakePHP (2.x) project. I have Users that have many Clients. The baked view for the client form includes a select box to choose the user the client is associated to. I would like to remove this field from the form and have it automatically set to the user that created the client. I know I probably need to do something in my Client model's beforeSave()
hook. What code do I put in that method to associate the newly created client with the user that is submitting the create form?
Asked
Active
Viewed 263 times
0
![](../../users/profiles/645029.webp)
Devin Crossman
- 6,816
- 10
- 54
- 96
1 Answers
0
In the action that the form is submitting to, just add the user data in before you run the save()
. Something like this:
//...
$postData['Client']['user_id'] = $this->Auth->user('id');
$this->Client->save($postData);
![](../../users/profiles/673664.webp)
Dave
- 27,341
- 18
- 106
- 177