これを保存する際に追加
[php]$this->request->data[‘Post’][‘user_id’] = $this->Auth->user(‘id’); [/php]
[php]
public function add() {
if ($this->request->is(‘post’)) {
$this->Post->create();
$this->request->data[‘Post’][‘user_id’] = $this->Auth->user(‘id’); //postテーブルのuser_idにログインしているユーザー情報を保存するよ
if ($this->Post->save($this->request->data)) {
$this->Session->setFlash(__(‘The post has been saved.’));
return $this->redirect(array(‘action’ => ‘index’));
} else {
$this->Session->setFlash(__(‘The post could not be saved. Please, try again.’));
}
}
$users = $this->Post->User->find(‘list’);
$this->set(compact(‘users’,’options’));
}
[/php]