聞きたいこと
CakePHPで、下に記載してあるController, View, Modelを使用してユーザー情報(username, email, password)の変更処理を実装しようと思っています。
ただ、Controllerで実際にユーザー情報(email)を変更し、DBに保存した後にmodify.ctpに遷移しても、inputタグのvalueに代入されている値が以前の値になってしまっています。
例えば)
変更前emailアドレスが、test01@example.comで変更後がtest02@example.comの場合、DBではtest02@example.comに変更されているのですが、再遷移した際のinputタグで変更されていない状態です。
自分で実施してみたこととしては、
- Chromeなどのセッション情報の削除
- $this->request->data['User']['email']をunset
などですが、いずれも解決できませんでした。
どなたかヒントを頂けると嬉しいです。
- UserController.php
: public function modify() { $this->loadModel('User'); if($this->request->is('post') || $this->request->is('put')){ if ($this->Staff->save($this->request->data, TRUE, array( 'email', ))) { $this->Flash->set(__('emailアドレスを変更しました')); $this->redirect($this->refer()); } else { $this->Flash->set(__('emailアドレスの変更に失敗しました')); } } } :
- modify.ctp
<?php : <p>username: </p> <?php echo $this->Form->input('username', [ 'type' => 'text', 'required' => false, ]); ?> <p>email: </p> <?php echo $this->Form->input('email', [ 'type' => 'email', 'required' => false, ]); ?> <p>password: </p> <?php echo $this->Form->input('password', [ 'type' => 'password', 'required' => false, ]); ?>
- User.php
<?php class User extends AppModel { : public $validate = array( 'email' => array( 'rule' => array('email'), 'message' => 'メールアドレスの形式ではありません', ) }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。