回答編集履歴
3
er
test
CHANGED
@@ -48,7 +48,7 @@
|
|
48
48
|
|
49
49
|
```PHP
|
50
50
|
|
51
|
-
function regist(){
|
51
|
+
function register(){
|
52
52
|
|
53
53
|
if($this->request->is('post')){
|
54
54
|
|
2
一例追記
test
CHANGED
@@ -37,3 +37,77 @@
|
|
37
37
|
}
|
38
38
|
|
39
39
|
```
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
2016/02/24 一例追記
|
44
|
+
|
45
|
+
---
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
```PHP
|
50
|
+
|
51
|
+
function regist(){
|
52
|
+
|
53
|
+
if($this->request->is('post')){
|
54
|
+
|
55
|
+
$this->Hoge->set($this->request->data);
|
56
|
+
|
57
|
+
if($this->Hoge->validates()){
|
58
|
+
|
59
|
+
// ポストされた情報を整理して保存する処理
|
60
|
+
|
61
|
+
$name = $this->request->data['Hoge']['first_name'].' '.$this->request->data['Hoge']['last_name'];
|
62
|
+
|
63
|
+
$address = $this->request->data['Hoge']['prefecture'].' '.$this->request->data['Hoge']['city'];
|
64
|
+
|
65
|
+
$save = array('Hoge' => array( 'name' => $name
|
66
|
+
|
67
|
+
, 'address' => $address
|
68
|
+
|
69
|
+
, 'category_id' => $this->request->data['Hoge']['category_id']
|
70
|
+
|
71
|
+
, 'email' => $this->request->data['Hoge']['email']
|
72
|
+
|
73
|
+
, 'is_delete' => false));
|
74
|
+
|
75
|
+
if($this->Hoge->save($save)){ // 敢えてもう一度バリデートは実行する
|
76
|
+
|
77
|
+
// 正常に保存出来たのでindexへ
|
78
|
+
|
79
|
+
$this->redirect(array('action' => 'index'));
|
80
|
+
|
81
|
+
}else{
|
82
|
+
|
83
|
+
// ユーザー入力ままのバリデートには成功しているのに保存出来なかった
|
84
|
+
|
85
|
+
// 恐らくバリデート後の情報整理のロジックに不備があったんだろう
|
86
|
+
|
87
|
+
// first_name,last_nameの文字数制限はOKだけど、nameの文字数は超過したとか
|
88
|
+
|
89
|
+
// ユーザーは悪くないのでサーバーエラーを返しておく
|
90
|
+
|
91
|
+
throw new InternalErrorException();
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
}else{
|
96
|
+
|
97
|
+
$this->Session->setFlash('入力内容に不備があります。', false);
|
98
|
+
|
99
|
+
}
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
// セレクトボックスの中身等、常にViewに渡したいものはここに書く
|
106
|
+
|
107
|
+
$this->set('category_items', $this->Category->find('list'));
|
108
|
+
|
109
|
+
}
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
```
|
1
推敲
test
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
|
13
|
-
Controller側のバリデートの呼び出し部分
|
13
|
+
Controller側のバリデートの呼び出し部分も確認してみてください。
|
14
14
|
|
15
15
|
確認に使ったController側のコードは↓です。
|
16
16
|
|