大家好,我使用的是 Cakephp 2.x。我有一个事件模型(表)和一个用户模型。保存事件后,我需要将当前登录的用户 ID 保存到事件模型的 user_id 字段中。我尝试过的代码已被注释。有任何想法吗?提前致谢。
public function add(){
//$this->loadModel('User');
if ($this->request->is('post')) {
$this->Event->create();
//$this->request->data['Event']['user_id'] = $this->request->data['User']['id'];
//$this->request->data['Event']['user_id'] = $this->request->data['User']['id'];
if ($this->Event->save($this->request->data)) {
$this->Session->setFlash(__('The event has been saved'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The event could not be saved. Please, try again.'));
}
}