質問編集履歴
19
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -192,7 +192,7 @@
|
|
192
192
|
|
193
193
|
```
|
194
194
|
|
195
|
-
**コントローラTestsController.php追記1**
|
195
|
+
> **コントローラTestsController.php追記1**
|
196
196
|
|
197
197
|
```TestsController.php
|
198
198
|
|
@@ -306,7 +306,7 @@
|
|
306
306
|
|
307
307
|
```
|
308
308
|
|
309
|
-
**テンプレートtest1.ctp追記1**
|
309
|
+
> **テンプレートtest1.ctp追記1**
|
310
310
|
|
311
311
|
```test1.ctp
|
312
312
|
|
18
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,12 +4,8 @@
|
|
4
4
|
|
5
5
|
フォームヘルパーから送られたパスワードの入力値(inputpass)とパスワード確認の入力値(inputpass2)をバリデーションのsameAsルールを使って一致しているかをチェックしたいのですが、
|
6
6
|
|
7
|
-
|
8
|
-
|
9
7
|
Error: TestsHelper could not be found.
|
10
8
|
|
11
|
-
|
12
|
-
|
13
9
|
というエラーがtest1ページで出力されて使えません。
|
14
10
|
|
15
11
|
> ==>上記は追記1で消えました。が、新たに
|
17
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,11 +4,11 @@
|
|
4
4
|
|
5
5
|
フォームヘルパーから送られたパスワードの入力値(inputpass)とパスワード確認の入力値(inputpass2)をバリデーションのsameAsルールを使って一致しているかをチェックしたいのですが、
|
6
6
|
|
7
|
-
|
7
|
+
|
8
8
|
|
9
9
|
Error: TestsHelper could not be found.
|
10
10
|
|
11
|
-
|
11
|
+
|
12
12
|
|
13
13
|
というエラーがtest1ページで出力されて使えません。
|
14
14
|
|
16
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
###質問概要
|
1
|
+
###質問概要(追記あり)
|
2
2
|
|
3
3
|
CakePHPのバリデーションについて
|
4
4
|
|
@@ -28,7 +28,7 @@
|
|
28
28
|
|
29
29
|
よろしくお願いします。
|
30
30
|
|
31
|
-
###前提
|
31
|
+
###前提(追記あり)
|
32
32
|
|
33
33
|
- SQLデータベースについて
|
34
34
|
|
15
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,13 +14,13 @@
|
|
14
14
|
|
15
15
|
> ==>上記は追記1で消えました。が、新たに
|
16
16
|
|
17
|
-
> ```ERROR
|
18
|
-
|
19
|
-
Error: Table "App\Model\Table\TestsTable" is not associated with "validationErrors"
|
17
|
+
> **Error: Table "App\Model\Table\TestsTable" is not associated with "validationErrors"**
|
20
|
-
|
21
|
-
|
18
|
+
|
22
|
-
|
23
|
-
|
19
|
+
というエラーが出ています。
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
|
24
24
|
|
25
25
|
下記に挙げるコードのどこが間違っているか、あるいは、
|
26
26
|
|
@@ -196,7 +196,7 @@
|
|
196
196
|
|
197
197
|
```
|
198
198
|
|
199
|
-
|
199
|
+
**コントローラTestsController.php追記1**
|
200
200
|
|
201
201
|
```TestsController.php
|
202
202
|
|
@@ -310,7 +310,7 @@
|
|
310
310
|
|
311
311
|
```
|
312
312
|
|
313
|
-
|
313
|
+
**テンプレートtest1.ctp追記1**
|
314
314
|
|
315
315
|
```test1.ctp
|
316
316
|
|
@@ -376,7 +376,9 @@
|
|
376
376
|
|
377
377
|
> ==>上記は追記1により解決しました。
|
378
378
|
|
379
|
+
新たに出ている
|
380
|
+
|
379
|
-
Error: Table "App\Model\Table\TestsTable" is not associated with "validationErrors"
|
381
|
+
**Error: Table "App\Model\Table\TestsTable" is not associated with "validationErrors"**
|
380
382
|
|
381
383
|
というエラー出力ですが、テーブルファイルの記述が間違っているのではないかと自分では考えています。
|
382
384
|
|
14
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,11 +16,11 @@
|
|
16
16
|
|
17
17
|
> ```ERROR
|
18
18
|
|
19
|
-
|
19
|
+
Error: Table "App\Model\Table\TestsTable" is not associated with "validationErrors"
|
20
|
-
|
20
|
+
|
21
|
-
|
21
|
+
```
|
22
|
-
|
22
|
+
|
23
|
-
というエラーが出ています。
|
23
|
+
> というエラーが出ています。
|
24
24
|
|
25
25
|
下記に挙げるコードのどこが間違っているか、あるいは、
|
26
26
|
|
13
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,7 +20,7 @@
|
|
20
20
|
|
21
21
|
> ```
|
22
22
|
|
23
|
-
|
23
|
+
というエラーが出ています。
|
24
24
|
|
25
25
|
下記に挙げるコードのどこが間違っているか、あるいは、
|
26
26
|
|
12
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,374 +14,374 @@
|
|
14
14
|
|
15
15
|
> ==>上記は追記1で消えました。が、新たに
|
16
16
|
|
17
|
-
```ERROR
|
17
|
+
> ```ERROR
|
18
|
+
|
19
|
+
> Error: Table "App\Model\Table\TestsTable" is not associated with "validationErrors"
|
20
|
+
|
21
|
+
> ```
|
22
|
+
|
23
|
+
> というエラーが出ています。
|
24
|
+
|
25
|
+
下記に挙げるコードのどこが間違っているか、あるいは、
|
26
|
+
|
27
|
+
バリデーションの書き方をご存知の方がいればご指摘頂きたく願います。
|
28
|
+
|
29
|
+
よろしくお願いします。
|
30
|
+
|
31
|
+
###前提
|
32
|
+
|
33
|
+
- SQLデータベースについて
|
34
|
+
|
35
|
+
CakePHPのSQL接続は完了し
|
36
|
+
|
37
|
+
Testsテーブルに
|
38
|
+
|
39
|
+
プライマリーキー、A_I_、のINTカラム「id」、
|
40
|
+
|
41
|
+
VARCHARカラム「inputpass」
|
42
|
+
|
43
|
+
がそれぞれ設定してあるとします。
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
- ページ遷移について
|
48
|
+
|
49
|
+
indexページから、test1ページにフォームの値をPOSTで送って
|
50
|
+
|
51
|
+
test1ページで値のチェックをするとします。
|
52
|
+
|
53
|
+
そして、saveメソッド、レコード追加はtest2ページでするものとして、
|
54
|
+
|
55
|
+
test1ページでは、値のチェック、エラー表示のみを行うものとします。
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
- モデルのテーブルファイル testsTable.php
|
60
|
+
|
61
|
+
```testsTable.php
|
62
|
+
|
63
|
+
<?php
|
64
|
+
|
65
|
+
namespace App\Model\Table;
|
66
|
+
|
67
|
+
use Cake\ORM\Table;
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
class TestsTable extends Table{
|
72
|
+
|
73
|
+
public function sameAs($a,$b) {
|
74
|
+
|
75
|
+
$v1 = array_shift($a);
|
76
|
+
|
77
|
+
$v2 = array_shift($b);
|
78
|
+
|
79
|
+
return $v1 == $v2;
|
80
|
+
|
81
|
+
}
|
82
|
+
|
83
|
+
public $validator = [
|
84
|
+
|
85
|
+
'inputpass' => [
|
86
|
+
|
87
|
+
'alphaNumeric' => [
|
88
|
+
|
89
|
+
'rule' => 'alphaNumeric',
|
90
|
+
|
91
|
+
'message' => '半角英数字のみで入力してください'
|
92
|
+
|
93
|
+
],
|
94
|
+
|
95
|
+
'minLength' => [
|
96
|
+
|
97
|
+
'rule' => ['minLength',6],
|
98
|
+
|
99
|
+
'message' => '6文字以上で入力してください'
|
100
|
+
|
101
|
+
]
|
102
|
+
|
103
|
+
],
|
104
|
+
|
105
|
+
'inputpass2' => [
|
106
|
+
|
107
|
+
'alphaNumeric' => [
|
108
|
+
|
109
|
+
'rule' => 'alphaNumeric',
|
110
|
+
|
111
|
+
'message' => '半角英数字のみで入力してください'
|
112
|
+
|
113
|
+
],
|
114
|
+
|
115
|
+
'minLength' => [
|
116
|
+
|
117
|
+
'rule' => ['minLength',6],
|
118
|
+
|
119
|
+
'message' => '6文字以上で入力してください'
|
120
|
+
|
121
|
+
]
|
122
|
+
|
123
|
+
'sameAs' => [
|
124
|
+
|
125
|
+
'rule' => ['sameAs','inputpass','inputpass2'],
|
126
|
+
|
127
|
+
'message' => 'パスワードが一致しません'
|
128
|
+
|
129
|
+
]
|
130
|
+
|
131
|
+
]
|
132
|
+
|
133
|
+
];
|
134
|
+
|
135
|
+
}
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
```
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
- コントローラ TestsController.php
|
144
|
+
|
145
|
+
```TestsController.php
|
146
|
+
|
147
|
+
<?php
|
148
|
+
|
149
|
+
namespace App\Controller;
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
class TestsController extends AppController {
|
154
|
+
|
155
|
+
public function initialize(){
|
156
|
+
|
157
|
+
$this->name = 'Tests';
|
158
|
+
|
159
|
+
$this->viewBuilder()->autoLayout(true);
|
160
|
+
|
161
|
+
$this->viewBuilder()->layout('tests');
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
public function index(){
|
166
|
+
|
167
|
+
$this->set('entity',$this->Tests->newEntity());
|
168
|
+
|
169
|
+
}
|
170
|
+
|
171
|
+
public function test1(){
|
172
|
+
|
173
|
+
if($this->request->isPost()){
|
174
|
+
|
175
|
+
$this->Tests->set($this->request->data);
|
176
|
+
|
177
|
+
}
|
178
|
+
|
179
|
+
public function test2(){
|
180
|
+
|
181
|
+
if ($this->request->is('post')){
|
182
|
+
|
183
|
+
$hoge = $this->Tests->newEntity($this->request->data);
|
184
|
+
|
185
|
+
$this->Tests->save($hoge);
|
186
|
+
|
187
|
+
}
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
}
|
192
|
+
|
193
|
+
}
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
```
|
198
|
+
|
199
|
+
> コントローラTestsController.php追記1
|
200
|
+
|
201
|
+
```TestsController.php
|
202
|
+
|
203
|
+
<?php
|
204
|
+
|
205
|
+
namespace App\Controller;
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
class TestsController extends AppController {
|
210
|
+
|
211
|
+
public function initialize(){
|
212
|
+
|
213
|
+
$this->name = 'Tests';
|
214
|
+
|
215
|
+
$this->viewBuilder()->autoLayout(true);
|
216
|
+
|
217
|
+
$this->viewBuilder()->layout('tests');
|
218
|
+
|
219
|
+
}
|
220
|
+
|
221
|
+
public function index(){
|
222
|
+
|
223
|
+
$this->set('entity',$this->Tests->newEntity());
|
224
|
+
|
225
|
+
}
|
226
|
+
|
227
|
+
public function test1(){
|
228
|
+
|
229
|
+
if($this->request->isPost()){
|
230
|
+
|
231
|
+
$this->Tests->set($this->request->data);
|
232
|
+
|
233
|
+
$this->Tests->set($hoge);
|
234
|
+
|
235
|
+
}else{
|
236
|
+
|
237
|
+
$error = $this->Tests->validationErrors;
|
238
|
+
|
239
|
+
$this->set('error',$error);
|
240
|
+
|
241
|
+
}
|
242
|
+
|
243
|
+
}
|
244
|
+
|
245
|
+
public function test2(){
|
246
|
+
|
247
|
+
if ($this->request->is('post')){
|
248
|
+
|
249
|
+
$hoge = $this->Tests->newEntity($this->request->data);
|
250
|
+
|
251
|
+
$this->Tests->save($hoge);
|
252
|
+
|
253
|
+
}
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
}
|
258
|
+
|
259
|
+
}
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
```
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
- テンプレートファイル test1.ctp
|
268
|
+
|
269
|
+
```test1.ctp
|
270
|
+
|
271
|
+
<?php
|
272
|
+
|
273
|
+
$error = array();
|
274
|
+
|
275
|
+
if($this->request->isPost()){
|
276
|
+
|
277
|
+
$this->Tests->set($this->request->data);
|
278
|
+
|
279
|
+
$inputpass = $this->request->data('inputpass');
|
280
|
+
|
281
|
+
$inputpass2 = $this->request->data('inputpass2');
|
282
|
+
|
283
|
+
if($this->Tests->validates()){
|
284
|
+
|
285
|
+
header("http://hoge/test2",true,303);
|
286
|
+
|
287
|
+
exit();
|
288
|
+
|
289
|
+
}else{
|
290
|
+
|
291
|
+
$error = $this->Tests->validationErrors;
|
292
|
+
|
293
|
+
}
|
294
|
+
|
295
|
+
}
|
296
|
+
|
297
|
+
if($this->request->isPost() && !is_null($error)){ ?>
|
298
|
+
|
299
|
+
<?=$this->Form->error('inputpass') ?>
|
300
|
+
|
301
|
+
<?=$this->Form->error('inputpass2') ?>
|
302
|
+
|
303
|
+
<?php } ?>
|
304
|
+
|
305
|
+
<br>
|
306
|
+
|
307
|
+
<a href="http://hoge/index.ctp">戻る</a>
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
```
|
312
|
+
|
313
|
+
> テンプレートtest1.ctp追記1
|
314
|
+
|
315
|
+
```test1.ctp
|
316
|
+
|
317
|
+
<?php
|
318
|
+
|
319
|
+
if($this->request->isPost()){
|
320
|
+
|
321
|
+
$this->Tests->set($this->request->data);
|
322
|
+
|
323
|
+
$inputpass = $this->request->data('inputpass');
|
324
|
+
|
325
|
+
$inputpass2 = $this->request->data('inputpass2');
|
326
|
+
|
327
|
+
if(is_null($error){
|
328
|
+
|
329
|
+
header("http://hoge/test2",true,303);
|
330
|
+
|
331
|
+
exit();
|
332
|
+
|
333
|
+
}
|
334
|
+
|
335
|
+
}
|
336
|
+
|
337
|
+
if($this->request->isPost() && !is_null($error)){ ?>
|
338
|
+
|
339
|
+
<?=$this->Form->error('inputpass') ?>
|
340
|
+
|
341
|
+
<?=$this->Form->error('inputpass2') ?>
|
342
|
+
|
343
|
+
<?php } ?>
|
344
|
+
|
345
|
+
<br>
|
346
|
+
|
347
|
+
<a href="http://hoge/index.ctp">戻る</a>
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
```
|
352
|
+
|
353
|
+
###自分で調べたこと
|
354
|
+
|
355
|
+
持っているCakePHPの参考書を読み倒してみると、バリデーションメソッドsameAsというのが、存在する様に書いてあるのですが、
|
356
|
+
|
357
|
+
あまり詳しい記述がなく
|
358
|
+
|
359
|
+
そのままだと使えなかったので、
|
360
|
+
|
361
|
+
今は自分でsameAsを定義して使おうとしています。
|
362
|
+
|
363
|
+
CakePHPの記事を検索エンジンでもかなり調べたのですが、
|
364
|
+
|
365
|
+
CakePHP自体の日本語記事が少ないこともあって、
|
366
|
+
|
367
|
+
解決できるものはありませんでした。
|
368
|
+
|
369
|
+
Error: UsersHelper could not be found.と出力されますが、
|
370
|
+
|
371
|
+
ヘルパーを用意しても解決しないので、
|
372
|
+
|
373
|
+
そもそもヘルパーを用意しなくても解決できる書き方が他にあって、
|
374
|
+
|
375
|
+
自分の書き方が間違っているのではないかと考えています。
|
376
|
+
|
377
|
+
> ==>上記は追記1により解決しました。
|
18
378
|
|
19
379
|
Error: Table "App\Model\Table\TestsTable" is not associated with "validationErrors"
|
20
380
|
|
21
|
-
```
|
22
|
-
|
23
|
-
というエラーが出ています。
|
24
|
-
|
25
|
-
|
381
|
+
というエラー出力ですが、テーブルファイルの記述が間違っているのではないかと自分では考えています。
|
26
|
-
|
382
|
+
|
383
|
+
|
384
|
+
|
27
|
-
バリデーションの書き方をご存知の方がいればご指摘
|
385
|
+
バリデーションを入力値チェックのみのページで使う書き方をご存知の方がいればご指摘してもらえると大変助かります。
|
28
386
|
|
29
387
|
よろしくお願いします。
|
30
|
-
|
31
|
-
###前提
|
32
|
-
|
33
|
-
- SQLデータベースについて
|
34
|
-
|
35
|
-
CakePHPのSQL接続は完了し
|
36
|
-
|
37
|
-
Testsテーブルに
|
38
|
-
|
39
|
-
プライマリーキー、A_I_、のINTカラム「id」、
|
40
|
-
|
41
|
-
VARCHARカラム「inputpass」
|
42
|
-
|
43
|
-
がそれぞれ設定してあるとします。
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
- ページ遷移について
|
48
|
-
|
49
|
-
indexページから、test1ページにフォームの値をPOSTで送って
|
50
|
-
|
51
|
-
test1ページで値のチェックをするとします。
|
52
|
-
|
53
|
-
そして、saveメソッド、レコード追加はtest2ページでするものとして、
|
54
|
-
|
55
|
-
test1ページでは、値のチェック、エラー表示のみを行うものとします。
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
- モデルのテーブルファイル testsTable.php
|
60
|
-
|
61
|
-
```testsTable.php
|
62
|
-
|
63
|
-
<?php
|
64
|
-
|
65
|
-
namespace App\Model\Table;
|
66
|
-
|
67
|
-
use Cake\ORM\Table;
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
class TestsTable extends Table{
|
72
|
-
|
73
|
-
public function sameAs($a,$b) {
|
74
|
-
|
75
|
-
$v1 = array_shift($a);
|
76
|
-
|
77
|
-
$v2 = array_shift($b);
|
78
|
-
|
79
|
-
return $v1 == $v2;
|
80
|
-
|
81
|
-
}
|
82
|
-
|
83
|
-
public $validator = [
|
84
|
-
|
85
|
-
'inputpass' => [
|
86
|
-
|
87
|
-
'alphaNumeric' => [
|
88
|
-
|
89
|
-
'rule' => 'alphaNumeric',
|
90
|
-
|
91
|
-
'message' => '半角英数字のみで入力してください'
|
92
|
-
|
93
|
-
],
|
94
|
-
|
95
|
-
'minLength' => [
|
96
|
-
|
97
|
-
'rule' => ['minLength',6],
|
98
|
-
|
99
|
-
'message' => '6文字以上で入力してください'
|
100
|
-
|
101
|
-
]
|
102
|
-
|
103
|
-
],
|
104
|
-
|
105
|
-
'inputpass2' => [
|
106
|
-
|
107
|
-
'alphaNumeric' => [
|
108
|
-
|
109
|
-
'rule' => 'alphaNumeric',
|
110
|
-
|
111
|
-
'message' => '半角英数字のみで入力してください'
|
112
|
-
|
113
|
-
],
|
114
|
-
|
115
|
-
'minLength' => [
|
116
|
-
|
117
|
-
'rule' => ['minLength',6],
|
118
|
-
|
119
|
-
'message' => '6文字以上で入力してください'
|
120
|
-
|
121
|
-
]
|
122
|
-
|
123
|
-
'sameAs' => [
|
124
|
-
|
125
|
-
'rule' => ['sameAs','inputpass','inputpass2'],
|
126
|
-
|
127
|
-
'message' => 'パスワードが一致しません'
|
128
|
-
|
129
|
-
]
|
130
|
-
|
131
|
-
]
|
132
|
-
|
133
|
-
];
|
134
|
-
|
135
|
-
}
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
```
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
- コントローラ TestsController.php
|
144
|
-
|
145
|
-
```TestsController.php
|
146
|
-
|
147
|
-
<?php
|
148
|
-
|
149
|
-
namespace App\Controller;
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
class TestsController extends AppController {
|
154
|
-
|
155
|
-
public function initialize(){
|
156
|
-
|
157
|
-
$this->name = 'Tests';
|
158
|
-
|
159
|
-
$this->viewBuilder()->autoLayout(true);
|
160
|
-
|
161
|
-
$this->viewBuilder()->layout('tests');
|
162
|
-
|
163
|
-
}
|
164
|
-
|
165
|
-
public function index(){
|
166
|
-
|
167
|
-
$this->set('entity',$this->Tests->newEntity());
|
168
|
-
|
169
|
-
}
|
170
|
-
|
171
|
-
public function test1(){
|
172
|
-
|
173
|
-
if($this->request->isPost()){
|
174
|
-
|
175
|
-
$this->Tests->set($this->request->data);
|
176
|
-
|
177
|
-
}
|
178
|
-
|
179
|
-
public function test2(){
|
180
|
-
|
181
|
-
if ($this->request->is('post')){
|
182
|
-
|
183
|
-
$hoge = $this->Tests->newEntity($this->request->data);
|
184
|
-
|
185
|
-
$this->Tests->save($hoge);
|
186
|
-
|
187
|
-
}
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
}
|
192
|
-
|
193
|
-
}
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
```
|
198
|
-
|
199
|
-
> コントローラTestsController.php追記1
|
200
|
-
|
201
|
-
```TestsController.php
|
202
|
-
|
203
|
-
<?php
|
204
|
-
|
205
|
-
namespace App\Controller;
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
class TestsController extends AppController {
|
210
|
-
|
211
|
-
public function initialize(){
|
212
|
-
|
213
|
-
$this->name = 'Tests';
|
214
|
-
|
215
|
-
$this->viewBuilder()->autoLayout(true);
|
216
|
-
|
217
|
-
$this->viewBuilder()->layout('tests');
|
218
|
-
|
219
|
-
}
|
220
|
-
|
221
|
-
public function index(){
|
222
|
-
|
223
|
-
$this->set('entity',$this->Tests->newEntity());
|
224
|
-
|
225
|
-
}
|
226
|
-
|
227
|
-
public function test1(){
|
228
|
-
|
229
|
-
if($this->request->isPost()){
|
230
|
-
|
231
|
-
$this->Tests->set($this->request->data);
|
232
|
-
|
233
|
-
$this->Tests->set($hoge);
|
234
|
-
|
235
|
-
}else{
|
236
|
-
|
237
|
-
$error = $this->Tests->validationErrors;
|
238
|
-
|
239
|
-
$this->set('error',$error);
|
240
|
-
|
241
|
-
}
|
242
|
-
|
243
|
-
}
|
244
|
-
|
245
|
-
public function test2(){
|
246
|
-
|
247
|
-
if ($this->request->is('post')){
|
248
|
-
|
249
|
-
$hoge = $this->Tests->newEntity($this->request->data);
|
250
|
-
|
251
|
-
$this->Tests->save($hoge);
|
252
|
-
|
253
|
-
}
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
}
|
258
|
-
|
259
|
-
}
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
```
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
- テンプレートファイル test1.ctp
|
268
|
-
|
269
|
-
```test1.ctp
|
270
|
-
|
271
|
-
<?php
|
272
|
-
|
273
|
-
$error = array();
|
274
|
-
|
275
|
-
if($this->request->isPost()){
|
276
|
-
|
277
|
-
$this->Tests->set($this->request->data);
|
278
|
-
|
279
|
-
$inputpass = $this->request->data('inputpass');
|
280
|
-
|
281
|
-
$inputpass2 = $this->request->data('inputpass2');
|
282
|
-
|
283
|
-
if($this->Tests->validates()){
|
284
|
-
|
285
|
-
header("http://hoge/test2",true,303);
|
286
|
-
|
287
|
-
exit();
|
288
|
-
|
289
|
-
}else{
|
290
|
-
|
291
|
-
$error = $this->Tests->validationErrors;
|
292
|
-
|
293
|
-
}
|
294
|
-
|
295
|
-
}
|
296
|
-
|
297
|
-
if($this->request->isPost() && !is_null($error)){ ?>
|
298
|
-
|
299
|
-
<?=$this->Form->error('inputpass') ?>
|
300
|
-
|
301
|
-
<?=$this->Form->error('inputpass2') ?>
|
302
|
-
|
303
|
-
<?php } ?>
|
304
|
-
|
305
|
-
<br>
|
306
|
-
|
307
|
-
<a href="http://hoge/index.ctp">戻る</a>
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
```
|
312
|
-
|
313
|
-
> テンプレートtest1.ctp追記1
|
314
|
-
|
315
|
-
```test1.ctp
|
316
|
-
|
317
|
-
<?php
|
318
|
-
|
319
|
-
if($this->request->isPost()){
|
320
|
-
|
321
|
-
$this->Tests->set($this->request->data);
|
322
|
-
|
323
|
-
$inputpass = $this->request->data('inputpass');
|
324
|
-
|
325
|
-
$inputpass2 = $this->request->data('inputpass2');
|
326
|
-
|
327
|
-
if(is_null($error){
|
328
|
-
|
329
|
-
header("http://hoge/test2",true,303);
|
330
|
-
|
331
|
-
exit();
|
332
|
-
|
333
|
-
}
|
334
|
-
|
335
|
-
}
|
336
|
-
|
337
|
-
if($this->request->isPost() && !is_null($error)){ ?>
|
338
|
-
|
339
|
-
<?=$this->Form->error('inputpass') ?>
|
340
|
-
|
341
|
-
<?=$this->Form->error('inputpass2') ?>
|
342
|
-
|
343
|
-
<?php } ?>
|
344
|
-
|
345
|
-
<br>
|
346
|
-
|
347
|
-
<a href="http://hoge/index.ctp">戻る</a>
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
```
|
352
|
-
|
353
|
-
###自分で調べたこと
|
354
|
-
|
355
|
-
持っているCakePHPの参考書を読み倒してみると、バリデーションメソッドsameAsというのが、存在する様に書いてあるのですが、
|
356
|
-
|
357
|
-
あまり詳しい記述がなく
|
358
|
-
|
359
|
-
そのままだと使えなかったので、
|
360
|
-
|
361
|
-
今は自分でsameAsを定義して使おうとしています。
|
362
|
-
|
363
|
-
CakePHPの記事を検索エンジンでもかなり調べたのですが、
|
364
|
-
|
365
|
-
CakePHP自体の日本語記事が少ないこともあって、
|
366
|
-
|
367
|
-
解決できるものはありませんでした。
|
368
|
-
|
369
|
-
Error: UsersHelper could not be found.と出力されますが、
|
370
|
-
|
371
|
-
ヘルパーを用意しても解決しないので、
|
372
|
-
|
373
|
-
そもそもヘルパーを用意しなくても解決できる書き方が他にあって、
|
374
|
-
|
375
|
-
自分の書き方が間違っているのではないかと考えています。
|
376
|
-
|
377
|
-
> ==>上記は追記1により解決しました。
|
378
|
-
|
379
|
-
Error: Table "App\Model\Table\TestsTable" is not associated with "validationErrors"
|
380
|
-
|
381
|
-
というエラー出力ですが、テーブルファイルの記述が間違っているのではないかと自分では考えています。
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
バリデーションを入力値チェックのみのページで使う書き方をご存知の方がいればご指摘してもらえると大変助かります。
|
386
|
-
|
387
|
-
よろしくお願いします。
|
11
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
|
13
13
|
というエラーがtest1ページで出力されて使えません。
|
14
14
|
|
15
|
-
==>上記は追記1で消えました。が、新たに
|
15
|
+
> ==>上記は追記1で消えました。が、新たに
|
16
16
|
|
17
17
|
```ERROR
|
18
18
|
|
@@ -196,7 +196,7 @@
|
|
196
196
|
|
197
197
|
```
|
198
198
|
|
199
|
-
|
199
|
+
> コントローラTestsController.php追記1
|
200
200
|
|
201
201
|
```TestsController.php
|
202
202
|
|
@@ -310,7 +310,7 @@
|
|
310
310
|
|
311
311
|
```
|
312
312
|
|
313
|
-
|
313
|
+
> テンプレートtest1.ctp追記1
|
314
314
|
|
315
315
|
```test1.ctp
|
316
316
|
|
@@ -374,7 +374,7 @@
|
|
374
374
|
|
375
375
|
自分の書き方が間違っているのではないかと考えています。
|
376
376
|
|
377
|
-
==>上記は追記1により解決しました。
|
377
|
+
> ==>上記は追記1により解決しました。
|
378
378
|
|
379
379
|
Error: Table "App\Model\Table\TestsTable" is not associated with "validationErrors"
|
380
380
|
|
10
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
|
13
13
|
というエラーがtest1ページで出力されて使えません。
|
14
14
|
|
15
|
-
==>上記は
|
15
|
+
==>上記は追記1で消えました。が、新たに
|
16
16
|
|
17
17
|
```ERROR
|
18
18
|
|
@@ -196,7 +196,7 @@
|
|
196
196
|
|
197
197
|
```
|
198
198
|
|
199
|
-
|
199
|
+
###コントローラTestsController.php追記1
|
200
200
|
|
201
201
|
```TestsController.php
|
202
202
|
|
@@ -310,7 +310,7 @@
|
|
310
310
|
|
311
311
|
```
|
312
312
|
|
313
|
-
|
313
|
+
###テンプレートtest1.ctp追記1
|
314
314
|
|
315
315
|
```test1.ctp
|
316
316
|
|
@@ -374,7 +374,7 @@
|
|
374
374
|
|
375
375
|
自分の書き方が間違っているのではないかと考えています。
|
376
376
|
|
377
|
-
==>上記は
|
377
|
+
==>上記は追記1により解決しました。
|
378
378
|
|
379
379
|
Error: Table "App\Model\Table\TestsTable" is not associated with "validationErrors"
|
380
380
|
|
9
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,7 +20,7 @@
|
|
20
20
|
|
21
21
|
```
|
22
22
|
|
23
|
-
|
23
|
+
というエラーが出ています。
|
24
24
|
|
25
25
|
下記に挙げるコードのどこが間違っているか、あるいは、
|
26
26
|
|
8
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -12,6 +12,16 @@
|
|
12
12
|
|
13
13
|
というエラーがtest1ページで出力されて使えません。
|
14
14
|
|
15
|
+
==>上記は修正1で消えました。が、新たに
|
16
|
+
|
17
|
+
```ERROR
|
18
|
+
|
19
|
+
Error: Table "App\Model\Table\TestsTable" is not associated with "validationErrors"
|
20
|
+
|
21
|
+
```
|
22
|
+
|
23
|
+
|
24
|
+
|
15
25
|
下記に挙げるコードのどこが間違っているか、あるいは、
|
16
26
|
|
17
27
|
バリデーションの書き方をご存知の方がいればご指摘頂きたく願います。
|
@@ -186,6 +196,74 @@
|
|
186
196
|
|
187
197
|
```
|
188
198
|
|
199
|
+
==>TestsController.php修正1
|
200
|
+
|
201
|
+
```TestsController.php
|
202
|
+
|
203
|
+
<?php
|
204
|
+
|
205
|
+
namespace App\Controller;
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
class TestsController extends AppController {
|
210
|
+
|
211
|
+
public function initialize(){
|
212
|
+
|
213
|
+
$this->name = 'Tests';
|
214
|
+
|
215
|
+
$this->viewBuilder()->autoLayout(true);
|
216
|
+
|
217
|
+
$this->viewBuilder()->layout('tests');
|
218
|
+
|
219
|
+
}
|
220
|
+
|
221
|
+
public function index(){
|
222
|
+
|
223
|
+
$this->set('entity',$this->Tests->newEntity());
|
224
|
+
|
225
|
+
}
|
226
|
+
|
227
|
+
public function test1(){
|
228
|
+
|
229
|
+
if($this->request->isPost()){
|
230
|
+
|
231
|
+
$this->Tests->set($this->request->data);
|
232
|
+
|
233
|
+
$this->Tests->set($hoge);
|
234
|
+
|
235
|
+
}else{
|
236
|
+
|
237
|
+
$error = $this->Tests->validationErrors;
|
238
|
+
|
239
|
+
$this->set('error',$error);
|
240
|
+
|
241
|
+
}
|
242
|
+
|
243
|
+
}
|
244
|
+
|
245
|
+
public function test2(){
|
246
|
+
|
247
|
+
if ($this->request->is('post')){
|
248
|
+
|
249
|
+
$hoge = $this->Tests->newEntity($this->request->data);
|
250
|
+
|
251
|
+
$this->Tests->save($hoge);
|
252
|
+
|
253
|
+
}
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
}
|
258
|
+
|
259
|
+
}
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
```
|
264
|
+
|
265
|
+
|
266
|
+
|
189
267
|
- テンプレートファイル test1.ctp
|
190
268
|
|
191
269
|
```test1.ctp
|
@@ -232,6 +310,46 @@
|
|
232
310
|
|
233
311
|
```
|
234
312
|
|
313
|
+
==>test1.ctp修正1
|
314
|
+
|
315
|
+
```test1.ctp
|
316
|
+
|
317
|
+
<?php
|
318
|
+
|
319
|
+
if($this->request->isPost()){
|
320
|
+
|
321
|
+
$this->Tests->set($this->request->data);
|
322
|
+
|
323
|
+
$inputpass = $this->request->data('inputpass');
|
324
|
+
|
325
|
+
$inputpass2 = $this->request->data('inputpass2');
|
326
|
+
|
327
|
+
if(is_null($error){
|
328
|
+
|
329
|
+
header("http://hoge/test2",true,303);
|
330
|
+
|
331
|
+
exit();
|
332
|
+
|
333
|
+
}
|
334
|
+
|
335
|
+
}
|
336
|
+
|
337
|
+
if($this->request->isPost() && !is_null($error)){ ?>
|
338
|
+
|
339
|
+
<?=$this->Form->error('inputpass') ?>
|
340
|
+
|
341
|
+
<?=$this->Form->error('inputpass2') ?>
|
342
|
+
|
343
|
+
<?php } ?>
|
344
|
+
|
345
|
+
<br>
|
346
|
+
|
347
|
+
<a href="http://hoge/index.ctp">戻る</a>
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
```
|
352
|
+
|
235
353
|
###自分で調べたこと
|
236
354
|
|
237
355
|
持っているCakePHPの参考書を読み倒してみると、バリデーションメソッドsameAsというのが、存在する様に書いてあるのですが、
|
@@ -256,6 +374,14 @@
|
|
256
374
|
|
257
375
|
自分の書き方が間違っているのではないかと考えています。
|
258
376
|
|
377
|
+
==>上記は修正1により解決しました。
|
378
|
+
|
379
|
+
Error: Table "App\Model\Table\TestsTable" is not associated with "validationErrors"
|
380
|
+
|
381
|
+
というエラー出力ですが、テーブルファイルの記述が間違っているのではないかと自分では考えています。
|
382
|
+
|
383
|
+
|
384
|
+
|
259
385
|
バリデーションを入力値チェックのみのページで使う書き方をご存知の方がいればご指摘してもらえると大変助かります。
|
260
386
|
|
261
387
|
よろしくお願いします。
|
7
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -46,7 +46,7 @@
|
|
46
46
|
|
47
47
|
|
48
48
|
|
49
|
-
- モデルのテーブルファイル
|
49
|
+
- モデルのテーブルファイル testsTable.php
|
50
50
|
|
51
51
|
```testsTable.php
|
52
52
|
|
@@ -130,7 +130,7 @@
|
|
130
130
|
|
131
131
|
|
132
132
|
|
133
|
-
- コントローラ
|
133
|
+
- コントローラ TestsController.php
|
134
134
|
|
135
135
|
```TestsController.php
|
136
136
|
|
@@ -186,7 +186,7 @@
|
|
186
186
|
|
187
187
|
```
|
188
188
|
|
189
|
-
- テンプレートファイル
|
189
|
+
- テンプレートファイル test1.ctp
|
190
190
|
|
191
191
|
```test1.ctp
|
192
192
|
|
6
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -186,9 +186,9 @@
|
|
186
186
|
|
187
187
|
```
|
188
188
|
|
189
|
-
- テンプレートファイル
|
189
|
+
- テンプレートファイル
|
190
|
-
|
190
|
+
|
191
|
-
```
|
191
|
+
```test1.ctp
|
192
192
|
|
193
193
|
<?php
|
194
194
|
|
5
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
```ERROR
|
8
8
|
|
9
|
-
Error:
|
9
|
+
Error: TestsHelper could not be found.
|
10
10
|
|
11
11
|
```
|
12
12
|
|
4
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
|
11
11
|
```
|
12
12
|
|
13
|
-
というエラーが出力されて使えません。
|
13
|
+
というエラーがtest1ページで出力されて使えません。
|
14
14
|
|
15
15
|
下記に挙げるコードのどこが間違っているか、あるいは、
|
16
16
|
|
@@ -46,163 +46,163 @@
|
|
46
46
|
|
47
47
|
|
48
48
|
|
49
|
+
- モデルのテーブルファイル
|
50
|
+
|
51
|
+
```testsTable.php
|
52
|
+
|
53
|
+
<?php
|
54
|
+
|
55
|
+
namespace App\Model\Table;
|
56
|
+
|
57
|
+
use Cake\ORM\Table;
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
class TestsTable extends Table{
|
62
|
+
|
63
|
+
public function sameAs($a,$b) {
|
64
|
+
|
65
|
+
$v1 = array_shift($a);
|
66
|
+
|
67
|
+
$v2 = array_shift($b);
|
68
|
+
|
69
|
+
return $v1 == $v2;
|
70
|
+
|
71
|
+
}
|
72
|
+
|
73
|
+
public $validator = [
|
74
|
+
|
75
|
+
'inputpass' => [
|
76
|
+
|
77
|
+
'alphaNumeric' => [
|
78
|
+
|
79
|
+
'rule' => 'alphaNumeric',
|
80
|
+
|
81
|
+
'message' => '半角英数字のみで入力してください'
|
82
|
+
|
83
|
+
],
|
84
|
+
|
85
|
+
'minLength' => [
|
86
|
+
|
87
|
+
'rule' => ['minLength',6],
|
88
|
+
|
89
|
+
'message' => '6文字以上で入力してください'
|
90
|
+
|
91
|
+
]
|
92
|
+
|
93
|
+
],
|
94
|
+
|
95
|
+
'inputpass2' => [
|
96
|
+
|
97
|
+
'alphaNumeric' => [
|
98
|
+
|
99
|
+
'rule' => 'alphaNumeric',
|
100
|
+
|
101
|
+
'message' => '半角英数字のみで入力してください'
|
102
|
+
|
103
|
+
],
|
104
|
+
|
105
|
+
'minLength' => [
|
106
|
+
|
107
|
+
'rule' => ['minLength',6],
|
108
|
+
|
109
|
+
'message' => '6文字以上で入力してください'
|
110
|
+
|
111
|
+
]
|
112
|
+
|
113
|
+
'sameAs' => [
|
114
|
+
|
115
|
+
'rule' => ['sameAs','inputpass','inputpass2'],
|
116
|
+
|
117
|
+
'message' => 'パスワードが一致しません'
|
118
|
+
|
119
|
+
]
|
120
|
+
|
121
|
+
]
|
122
|
+
|
123
|
+
];
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
```
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
- コントローラ
|
134
|
+
|
135
|
+
```TestsController.php
|
136
|
+
|
137
|
+
<?php
|
138
|
+
|
139
|
+
namespace App\Controller;
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
class TestsController extends AppController {
|
144
|
+
|
145
|
+
public function initialize(){
|
146
|
+
|
147
|
+
$this->name = 'Tests';
|
148
|
+
|
149
|
+
$this->viewBuilder()->autoLayout(true);
|
150
|
+
|
151
|
+
$this->viewBuilder()->layout('tests');
|
152
|
+
|
153
|
+
}
|
154
|
+
|
155
|
+
public function index(){
|
156
|
+
|
157
|
+
$this->set('entity',$this->Tests->newEntity());
|
158
|
+
|
159
|
+
}
|
160
|
+
|
161
|
+
public function test1(){
|
162
|
+
|
163
|
+
if($this->request->isPost()){
|
164
|
+
|
165
|
+
$this->Tests->set($this->request->data);
|
166
|
+
|
167
|
+
}
|
168
|
+
|
169
|
+
public function test2(){
|
170
|
+
|
171
|
+
if ($this->request->is('post')){
|
172
|
+
|
173
|
+
$hoge = $this->Tests->newEntity($this->request->data);
|
174
|
+
|
175
|
+
$this->Tests->save($hoge);
|
176
|
+
|
177
|
+
}
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
}
|
182
|
+
|
183
|
+
}
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
```
|
188
|
+
|
49
|
-
-
|
189
|
+
- テンプレートファイル test1.ctp
|
50
190
|
|
51
191
|
```CakePHP
|
52
192
|
|
53
193
|
<?php
|
54
194
|
|
55
|
-
namespace App\Model\Table;
|
56
|
-
|
57
|
-
use Cake\ORM\Table;
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
class TestsTable extends Table{
|
62
|
-
|
63
|
-
public function sameAs($a,$b) {
|
64
|
-
|
65
|
-
$v1 = array_shift($a);
|
66
|
-
|
67
|
-
$v2 = array_shift($b);
|
68
|
-
|
69
|
-
return $v1 == $v2;
|
70
|
-
|
71
|
-
}
|
72
|
-
|
73
|
-
public $validator = [
|
74
|
-
|
75
|
-
'inputpass' => [
|
76
|
-
|
77
|
-
'alphaNumeric' => [
|
78
|
-
|
79
|
-
'rule' => 'alphaNumeric',
|
80
|
-
|
81
|
-
'message' => '半角英数字のみで入力してください'
|
82
|
-
|
83
|
-
],
|
84
|
-
|
85
|
-
'minLength' => [
|
86
|
-
|
87
|
-
'rule' => ['minLength',6],
|
88
|
-
|
89
|
-
'message' => '6文字以上で入力してください'
|
90
|
-
|
91
|
-
]
|
92
|
-
|
93
|
-
],
|
94
|
-
|
95
|
-
'inputpass2' => [
|
96
|
-
|
97
|
-
'alphaNumeric' => [
|
98
|
-
|
99
|
-
'rule' => 'alphaNumeric',
|
100
|
-
|
101
|
-
'message' => '半角英数字のみで入力してください'
|
102
|
-
|
103
|
-
],
|
104
|
-
|
105
|
-
'minLength' => [
|
106
|
-
|
107
|
-
'rule' => ['minLength',6],
|
108
|
-
|
109
|
-
'message' => '6文字以上で入力してください'
|
110
|
-
|
111
|
-
]
|
112
|
-
|
113
|
-
'sameAs' => [
|
114
|
-
|
115
|
-
'rule' => ['sameAs','inputpass','inputpass2'],
|
116
|
-
|
117
|
-
'message' => 'パスワードが一致しません'
|
118
|
-
|
119
|
-
]
|
120
|
-
|
121
|
-
]
|
122
|
-
|
123
|
-
];
|
124
|
-
|
125
|
-
}
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
```
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
- コントローラ TestsController.php
|
134
|
-
|
135
|
-
```CakePHP
|
136
|
-
|
137
|
-
<?php
|
138
|
-
|
139
|
-
namespace App\Controller;
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
class TestsController extends AppController {
|
144
|
-
|
145
|
-
public function initialize(){
|
146
|
-
|
147
|
-
$this->name = 'Tests';
|
148
|
-
|
149
|
-
$this->viewBuilder()->autoLayout(true);
|
150
|
-
|
151
|
-
$this->viewBuilder()->layout('tests');
|
152
|
-
|
153
|
-
}
|
154
|
-
|
155
|
-
public function index(){
|
156
|
-
|
157
|
-
$this->set('entity',$this->Tests->newEntity());
|
158
|
-
|
159
|
-
}
|
160
|
-
|
161
|
-
public function test1(){
|
162
|
-
|
163
|
-
if($this->request->isPost()){
|
164
|
-
|
165
|
-
$this->Tests->set($this->request->data);
|
166
|
-
|
167
|
-
}
|
168
|
-
|
169
|
-
public function test2(){
|
170
|
-
|
171
|
-
if ($this->request->is('post')){
|
172
|
-
|
173
|
-
$hoge = $this->Tests->newEntity($this->request->data);
|
174
|
-
|
175
|
-
$this->Tests->save($hoge);
|
176
|
-
|
177
|
-
}
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
}
|
182
|
-
|
183
|
-
}
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
```
|
188
|
-
|
189
|
-
- テンプレートファイル test1.ctp
|
190
|
-
|
191
|
-
```CakePHP
|
192
|
-
|
193
|
-
<?php
|
194
|
-
|
195
195
|
$error = array();
|
196
196
|
|
197
197
|
if($this->request->isPost()){
|
198
198
|
|
199
|
-
$this->
|
199
|
+
$this->Tests->set($this->request->data);
|
200
200
|
|
201
201
|
$inputpass = $this->request->data('inputpass');
|
202
202
|
|
203
203
|
$inputpass2 = $this->request->data('inputpass2');
|
204
204
|
|
205
|
-
if($this->
|
205
|
+
if($this->Tests->validates()){
|
206
206
|
|
207
207
|
header("http://hoge/test2",true,303);
|
208
208
|
|
@@ -210,7 +210,7 @@
|
|
210
210
|
|
211
211
|
}else{
|
212
212
|
|
213
|
-
$error = $this->
|
213
|
+
$error = $this->Tests->validationErrors;
|
214
214
|
|
215
215
|
}
|
216
216
|
|
@@ -218,14 +218,10 @@
|
|
218
218
|
|
219
219
|
if($this->request->isPost() && !is_null($error)){ ?>
|
220
220
|
|
221
|
-
<?=$this->Form->error('inputid') ?>
|
222
|
-
|
223
221
|
<?=$this->Form->error('inputpass') ?>
|
224
222
|
|
225
223
|
<?=$this->Form->error('inputpass2') ?>
|
226
224
|
|
227
|
-
<?=$this->Form->error('email') ?>
|
228
|
-
|
229
225
|
<?php } ?>
|
230
226
|
|
231
227
|
<br>
|
3
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -258,7 +258,7 @@
|
|
258
258
|
|
259
259
|
そもそもヘルパーを用意しなくても解決できる書き方が他にあって、
|
260
260
|
|
261
|
-
自分の書き方が間違っているではないかと考えています。
|
261
|
+
自分の書き方が間違っているのではないかと考えています。
|
262
262
|
|
263
263
|
バリデーションを入力値チェックのみのページで使う書き方をご存知の方がいればご指摘してもらえると大変助かります。
|
264
264
|
|
2
大幅修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
CakePHP3のバリデーション
|
1
|
+
CakePHP3のバリデーションの使い方
|
test
CHANGED
@@ -2,13 +2,11 @@
|
|
2
2
|
|
3
3
|
CakePHPのバリデーションについて
|
4
4
|
|
5
|
-
フォームヘルパーから送られたパスワードの入力値(inputpass)とパスワード確認の入力値(inputpass2)をsameAsルールを使って一致しているかをチェックしたいのですが、
|
5
|
+
フォームヘルパーから送られたパスワードの入力値(inputpass)とパスワード確認の入力値(inputpass2)をバリデーションのsameAsルールを使って一致しているかをチェックしたいのですが、
|
6
6
|
|
7
7
|
```ERROR
|
8
8
|
|
9
|
-
Error: s
|
9
|
+
Error: UsersHelper could not be found.
|
10
|
-
|
11
|
-
|
12
10
|
|
13
11
|
```
|
14
12
|
|
@@ -16,7 +14,7 @@
|
|
16
14
|
|
17
15
|
下記に挙げるコードのどこが間違っているか、あるいは、
|
18
16
|
|
19
|
-
書き方をご存知の方がいればご指摘頂きたく願います。
|
17
|
+
バリデーションの書き方をご存知の方がいればご指摘頂きたく願います。
|
20
18
|
|
21
19
|
よろしくお願いします。
|
22
20
|
|
@@ -44,7 +42,7 @@
|
|
44
42
|
|
45
43
|
そして、saveメソッド、レコード追加はtest2ページでするものとして、
|
46
44
|
|
47
|
-
test1ページでは、値のチェックのみを行うものとします。
|
45
|
+
test1ページでは、値のチェック、エラー表示のみを行うものとします。
|
48
46
|
|
49
47
|
|
50
48
|
|
@@ -188,9 +186,55 @@
|
|
188
186
|
|
189
187
|
```
|
190
188
|
|
191
|
-
- テンプレートファイル
|
189
|
+
- テンプレートファイル test1.ctp
|
190
|
+
|
192
|
-
|
191
|
+
```CakePHP
|
192
|
+
|
193
|
+
<?php
|
194
|
+
|
195
|
+
$error = array();
|
196
|
+
|
197
|
+
if($this->request->isPost()){
|
198
|
+
|
193
|
-
test
|
199
|
+
$this->Users->set($this->request->data);
|
200
|
+
|
201
|
+
$inputpass = $this->request->data('inputpass');
|
202
|
+
|
203
|
+
$inputpass2 = $this->request->data('inputpass2');
|
204
|
+
|
205
|
+
if($this->Users->validates()){
|
206
|
+
|
207
|
+
header("http://hoge/test2",true,303);
|
208
|
+
|
209
|
+
exit();
|
210
|
+
|
211
|
+
}else{
|
212
|
+
|
213
|
+
$error = $this->Users->validationErrors;
|
214
|
+
|
215
|
+
}
|
216
|
+
|
217
|
+
}
|
218
|
+
|
219
|
+
if($this->request->isPost() && !is_null($error)){ ?>
|
220
|
+
|
221
|
+
<?=$this->Form->error('inputid') ?>
|
222
|
+
|
223
|
+
<?=$this->Form->error('inputpass') ?>
|
224
|
+
|
225
|
+
<?=$this->Form->error('inputpass2') ?>
|
226
|
+
|
227
|
+
<?=$this->Form->error('email') ?>
|
228
|
+
|
229
|
+
<?php } ?>
|
230
|
+
|
231
|
+
<br>
|
232
|
+
|
233
|
+
<a href="http://hoge/index.ctp">戻る</a>
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
```
|
194
238
|
|
195
239
|
###自分で調べたこと
|
196
240
|
|
@@ -202,16 +246,20 @@
|
|
202
246
|
|
203
247
|
今は自分でsameAsを定義して使おうとしています。
|
204
248
|
|
205
|
-
もし、CakePHP3のデフォルトで用意されているsameAsの使い方を知っている方がいれば、そちらの書き方が知りたいです。
|
206
|
-
|
207
|
-
仮にデフォルトのsameAsメソッドを使えないとしても、sameAsを定義してメソッドとして使いたいです。
|
208
|
-
|
209
249
|
CakePHPの記事を検索エンジンでもかなり調べたのですが、
|
210
250
|
|
211
251
|
CakePHP自体の日本語記事が少ないこともあって、
|
212
252
|
|
213
253
|
解決できるものはありませんでした。
|
214
254
|
|
255
|
+
Error: UsersHelper could not be found.と出力されますが、
|
256
|
+
|
257
|
+
ヘルパーを用意しても解決しないので、
|
258
|
+
|
259
|
+
そもそもヘルパーを用意しなくても解決できる書き方が他にあって、
|
260
|
+
|
261
|
+
自分の書き方が間違っているではないかと考えています。
|
262
|
+
|
215
|
-
書き方をご存知の方がいればご指摘してもらえると大変助かります。
|
263
|
+
バリデーションを入力値チェックのみのページで使う書き方をご存知の方がいればご指摘してもらえると大変助かります。
|
216
264
|
|
217
265
|
よろしくお願いします。
|
1
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
というエラーが出力されて使えません。
|
16
16
|
|
17
|
-
下記に挙げるコードのどこが間違っているか、
|
17
|
+
下記に挙げるコードのどこが間違っているか、あるいは、
|
18
18
|
|
19
19
|
書き方をご存知の方がいればご指摘頂きたく願います。
|
20
20
|
|