質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
CakePHP

CakePHPは、PHPで書かれたWebアプリケーション開発用のフレームワークです。 Ruby on Railsの考え方を多く取り入れており、Railsの高速性とPHPの機動性を兼ね備えています。 MVCやORMなどを「規約優先の考え方」で利用するため、コードを書く手間を省くことができます。 外部のライブラリに依存しないので、単体での利用が可能です。

Q&A

解決済

1回答

820閲覧

CakePHPでユーザー情報の編集画面がうまく作動しません。

amaturePy

総合スコア131

CakePHP

CakePHPは、PHPで書かれたWebアプリケーション開発用のフレームワークです。 Ruby on Railsの考え方を多く取り入れており、Railsの高速性とPHPの機動性を兼ね備えています。 MVCやORMなどを「規約優先の考え方」で利用するため、コードを書く手間を省くことができます。 外部のライブラリに依存しないので、単体での利用が可能です。

0グッド

0クリップ

投稿2019/06/18 22:59

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'); ?> コード

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

m.ts10806

2019/06/18 23:13

ルーティングとprofile()に引数で受け取っている$idがちゃんと来ているか確認してください。 また、下記の一行は何がしたいのでしょうか $this->User->$id;
amaturePy

2019/06/19 01:02 編集

$this->User->$id; debug($id); としたところnullで返ってきました。 ネットの参考にしたコードに付いていたもので、私自身、その役割がわからないまま使用しておりました。特に何か役割を持っているようではないので、コメントアウトしました。
guest

回答1

0

自己解決

public function find() { $userNameKeyword=$this->request->data['Users']['username']; $users=$this->User->find('all',[ 'conditions' => [ 'User.username LIKE' => '%'.$userNameKeyword.'%' ],]); $this->set('users',$users); $this->render(); } コード
<div class="row-fluid"> <div class="span9"> <table class="table"> <tr> <th><?php echo $this->Paginator->sort('id','ID');?></th> <th><?php echo $this->Paginator->sort('username','Username');?></th> </tr> <?php foreach($users as $key => $user):?> <tr> <td><?php echo h($user['User']['id']); ?></td> <td><?php echo $this->Html->link($user['User']['username'],'/follows/profile/' . $user['User']['id']);?></td> </tr> <?php endforeach;?> </table> </div> <div class="span3"> <div class="well" style="margin-top:20px;"> <?php echo $this->Form->create('Users',array('url'=>'find')); ?> <fieldset> <legend>Search user</legend> </fieldset> <?php echo $this->Form->input('username', array('label' => 'Enter Username', 'class' => 'span12', 'empty' => true)); ?> <?php echo $this->Form->end('Search'); ?> </div> </div> </div> コード

投稿2019/06/23 02:09

amaturePy

総合スコア131

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

rgewgeg

2020/06/17 12:28

えっと...解説はしていただいてもよろしいでしょうか...
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問