【PHP】フレームワーク CakePHP 17ホール目【v2.4】
■ このスレッドは過去ログ倉庫に格納されています
0765nobodyさん
2014/06/22(日) 12:51:34.63ID:???insertは問題ないのですがupdateが上手くいきません。
(上書きされずに毎回insertされる)
saveメソッドでupdateするには主キーを渡す必要があるのは分かっているのですが、
その方法がよく分かりません。このような場合はどうすれば良いのでしょうか?
usesテーブル
-id//主キー
-username
-password
profilesテーブル
-id//主キー
-user_id//外部キー
-birthday
class ProfilesController extends AppController{
public function edit(){
$id=$this->Auth->user('id');
if($this->request->is(array('post','put'))) {
$this->request->data['Profile']['user_id'] = $id;
if ($this->Profile->save($this->request->data)) {
$this->Session->setFlash(__('The profile has been saved.'));
} } }
テーブルを1つにまとめてしまえば話しは早いのですが
別の都合でそれができません。
■ このスレッドは過去ログ倉庫に格納されています