bakeで生成した既成のaddアクションとeditアクションをかいつまんで記事の複製機能(duplicateアクション)を実装しようと思いましたが、うまくいきません。
どうやってもsaveが失敗してエラー処理側に入ってしまいます。
実装するうえでのポイントをご教示いただけないでしょうか。
UserController.php
duplicate action
php
1 $new_user = $this->Users->newEntity(); 2 if ($this->request->is(['patch', 'post', 'put'])) { 3 $new_user = $this->Users->patchEntity($new_user, $this->request->data); 4 if ($this->Users->save($new_user)) { 5 $this->Flash->success(__('The user has been saved.')); 6 return $this->redirect(['action' => 'index']); 7 } else { 8 $this->Flash->error(__('The user could not be saved. Please, try again.')); 9 } 10 } 11 $user = $this->Users->get($id, [ 12 'contain' => ['Companies'] 13 ]); 14 $companies = $this->Users->Companies->find('list', ['limit' => 200]); 15 $this->set(compact('user', 'companies')); 16 $this->set('_serialize', ['user']);
duplicate.ctp
php
1 <?= $this->Form->create($user) ?> 2 <fieldset> 3 <legend><?= __('Edit User') ?></legend> 4 <?php 5 echo $this->Form->input('companies_id', ['options' => $companies]); 6 echo $this->Form->input('name'); 7 echo $this->Form->input('mail'); 8 echo $this->Form->input('login_name'); 9 echo $this->Form->input('login_password'); 10 echo $this->Form->input('image'); 11 echo $this->Form->input('cookie'); 12 echo $this->Form->input('administrator_flg'); 13 echo $this->Form->input('deleted', ['empty' => true]); 14 ?> 15 </fieldset> 16 <?= $this->Form->button(__('Submit')) ?> 17 <?= $this->Form->end() ?>
よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/03/21 09:07 編集
2016/03/21 09:14
2016/03/21 10:09
2016/03/21 10:10
2016/03/21 10:11
2016/03/21 12:12
2016/03/21 12:24