CakePHPのコントローラーの変数にctpファイルのフォームから値を送り、格納させたいのですが、うまく変数($id)に入りません。こちらのコードで何か問題がありましたらご指摘をお願いしたいです。
profile関数はユーザー情報の編集機能
この$idにPOSTの値を入れたいと考えてます。
また、下記のecho"1","2"はデバックのために記載しました。
その結果echo"2"の行が反応していないと分かりました。
エラー内容「Undefined variable: id」
profile.ctp Users/profilectp
<?php echo $this->Form->create('Users',array('action'=>'profile')); echo $this->Form->hidden('username',['username']); echo $this->Form->hidden('pass',['password']); echo $this->Form->hidden('email',['email']); echo $this->Form->end('Save'); ?> コード
Controller/ProfileController.php
public function profile() { $id=$this->request->data('profile'); //$this->request->$id('profile'); echo $id; if (!$id) { echo "1"; //throw new NotFoundException(__('Invalid user')); } $user = $this->Post->findById($id); if(!$user) { echo "2";// throw new NotFoundException(__('Invalid user')); } if($this->request->is(array('post','put'))) { $this->post->id = $id; if($this->post->save($this->request->data)) { $this->Flash->seccess(__('Your information could be updated')); return $this->redirect(array('action'=>'edit')); } $this->Flash->error(__('Unable to update your information')); } if(!$this->request->data) { $this->request->data = $post; } } コード

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/06/04 01:52
2019/06/04 02:03
2019/06/04 02:30
2019/06/04 02:32
2019/06/04 02:39 編集
2019/06/04 04:01
2019/06/04 04:15
2019/06/04 13:01
2019/06/04 23:24
2019/06/05 01:15