CakePHPにおいて、SNSのようなアプリを作成しております。
その中で、ユーザー情報の編集画面(ただパスワードを編集)できる機能profileというアクションを作成したのですが、passwordを入力したとしても、パスワード変更完了のメッセージがうまく表示されません。
常にInvalid Userが表示されてしまうので、The user has been savedと成功時の文言を表示するにはどのようにコードを変更すればよろしいいでしょうか?
UsersController.php public function profile($id=null) { $this->User->$id; if(!$this->User->exists()) { throw new NotFoundException(__('Invalid user')); } if($this->request->is('post')) { if($this->Auth->user('password')==AuthComponent::password($this->request->data['User']['passowrd'])) { if($this->User->save($this->request->data)) { $this->Session->setFlash(__('The user has been saved')); $this->redirect(array('action'=>'profile')); }else{ $this->Session->setFlash(__('The user could not be saved.Please try again.')); $this->Session->selfFlash(__('Incorrect password.')); } }else $this->request->data = $this->User->read(null,$id); } } コード
profile.ctp <p>Modify your account settings</p> <?php echo $this->Session->flash(); ?> <?php echo $this->Form->create('User'); echo $this->Form->input('currentPassword', array('type' => 'password')); //echo $this->Form->input('username', array('disabled' => 'disabled', 'value' => $username)); echo $this->Form->input('newPassword', array('type' => 'password')); echo $this->Form->end('Update'); ?> コード
回答1件
あなたの回答
tips
プレビュー