質問編集履歴
1
『Model/Entity/User\.php』および『Model/Table/UsersTable\.php』を追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -62,6 +62,148 @@
|
|
62
62
|
|
63
63
|
```
|
64
64
|
|
65
|
+
Model/Entity/User.php
|
66
|
+
|
67
|
+
```
|
68
|
+
|
69
|
+
<?php
|
70
|
+
|
71
|
+
namespace App\Model\Entity;
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
use Cake\ORM\Entity;
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
class User extends Entity
|
80
|
+
|
81
|
+
{
|
82
|
+
|
83
|
+
protected $_accessible = [
|
84
|
+
|
85
|
+
'*' => true,
|
86
|
+
|
87
|
+
'id' => false,
|
88
|
+
|
89
|
+
];
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
protected $_hidden = [
|
94
|
+
|
95
|
+
'passwd'
|
96
|
+
|
97
|
+
];
|
98
|
+
|
99
|
+
}
|
100
|
+
|
101
|
+
```
|
102
|
+
|
103
|
+
Model/Table/UsersTable.php
|
104
|
+
|
105
|
+
```
|
106
|
+
|
107
|
+
<?php
|
108
|
+
|
109
|
+
namespace App\Model\Table;
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
use App\Model\Entity\User;
|
114
|
+
|
115
|
+
use Cake\ORM\Query;
|
116
|
+
|
117
|
+
use Cake\ORM\RulesChecker;
|
118
|
+
|
119
|
+
use Cake\ORM\Table;
|
120
|
+
|
121
|
+
use Cake\Validation\Validator;
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
class UsersTable extends Table
|
126
|
+
|
127
|
+
{
|
128
|
+
|
129
|
+
public function initialize(array $config)
|
130
|
+
|
131
|
+
{
|
132
|
+
|
133
|
+
parent::initialize($config);
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
$this->table('users');
|
138
|
+
|
139
|
+
$this->displayField('id');
|
140
|
+
|
141
|
+
$this->primaryKey('id');
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
$this->addBehavior('Timestamp');
|
146
|
+
|
147
|
+
}
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
public function validationDefault(Validator $validator)
|
152
|
+
|
153
|
+
{
|
154
|
+
|
155
|
+
$validator
|
156
|
+
|
157
|
+
->allowEmpty('id', 'create');
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
$validator
|
162
|
+
|
163
|
+
->requirePresence('name', 'create')
|
164
|
+
|
165
|
+
->notEmpty('name');
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
$validator
|
170
|
+
|
171
|
+
->email('email')
|
172
|
+
|
173
|
+
->requirePresence('email', 'create')
|
174
|
+
|
175
|
+
->notEmpty('email');
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
$validator
|
180
|
+
|
181
|
+
->requirePresence('passwd', 'create')
|
182
|
+
|
183
|
+
->notEmpty('passwd');
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
return $validator;
|
188
|
+
|
189
|
+
}
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
public function buildRules(RulesChecker $rules)
|
194
|
+
|
195
|
+
{
|
196
|
+
|
197
|
+
$rules->add($rules->isUnique(['email']));
|
198
|
+
|
199
|
+
return $rules;
|
200
|
+
|
201
|
+
}
|
202
|
+
|
203
|
+
}
|
204
|
+
|
205
|
+
```
|
206
|
+
|
65
207
|
|
66
208
|
|
67
209
|
テーブル情報
|