はじめまして!
CakePHPのedit機能を利用して、プロフィールの編集画面を実装しようとしている者です。
以下のコードを使用すると、
①編集画面に、既に登録されている名前やメリット等の情報が出てこない。
②保存をすると、ユーザーid(user_id)が「0」になってしまい、本来のユーザーidが格納されない。
普通のeditコードと違う点は、編集するidデータをAuthコンポーネントから利用している点のみです。
どうすれば正常に機能出来るでしょうか?
是非ご指導のほどよろしくお願い申し上げます。
lang
1//ProfilesController.php 2 public function edit() { 3 4 $user = AuthComponent::user('id'); 5 $this->Profile->user_id = $user; 6 7 if ($this->request->is('get')) { 8 $this->request->data = $this->Profile->read(); //①編集画面に、既に登録されている名前やメリット等の情報が出てこない 9 } else { 10 if ($this->Profile->save($this->request->data)) { //②保存をすると、ユーザーid(user_id)が「0」になってしまい、本来のユーザーidが格納されない。 11 $this->Session->setFlash('Success!'); 12 $this->redirect(array('action'=>'index')); 13 } else { 14 $this->Session->setFlash('Failed!'); 15 } 16 } 17 } 18
lang
1//edit.ctp 2<h2>プロフィールの編集</h2> 3 4<?php 5echo $this->Form->create('Profile', array('action'=>'edit')); 6echo $this->Form->input('name'); 7echo $this->Form->input('merit'); 8echo $this->Form->input('career'); 9echo $this->Form->end('保存'); 10?>

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。