当注册操作尝试保存数据时,没有任何反应并且用户返回到同一页面
经过一些调试后,我在运行 '$this->Participant->create()' 时发现它没有返回新的 id
if ($this->request->is('post') || $this->request->is('put')) {
if (!isset($this->data['Participant']['typeSel'])) {
$regType = $this->data['Participant']['type'];
// for pilots and visitors, copy the name/email from TeamMember to Participant
if ($regType == 'pilot' || $regType == 'visitor') {
$this->request->data['Participant']['name'] =
ucwords(strtolower($this->request->data['TeamMember'][0]['first_name'])) . ' '
. ucwords(strtolower($this->request->data['TeamMember'][0]['family_name']));
$this->request->data['Participant']['email'] = $this->request->data['TeamMember'][0]['email'];
}
// mark valid inside the team (if not joining)
if ($regType != 'jointeam') {
foreach ($this->request->data['TeamMember'] as & $teamMember) {
$teamMember['validate_inteam'] = 'yes';
if ($regType == 'visitor') {
$teamMember['free_entrance'] = 'yes';
$teamMember['num_tables'] = 0;
}
}
$numTeamMembers = count($this->data['TeamMember']);
}
// set password
$this->request->data['Participant']['password'] =
Security::hash($this->data['Participant']['password1'], null, true);
// perform registration itself
if ($regType == 'jointeam') {
$this->TeamMember->create($this->request->data);
if ($this->TeamMember->save($this->request->data)) {
$this->Session->setFlash('Your registration was recorded. An email was dispatched to the team coordinator for approval.');
$this->Mail->sendTeamValidationEmail(
$this->Participant->findById($this->data['TeamMember']['participant_id']));
$this->redirect(array(
'controller' => 'pages',
'action' => 'welcome'));
}
else {
$this->Session->setFlash('Your registration could not be completed. Please try again.');
}
}
else {
$this->Participant->create(); // $this->Participant->id remains empty
if ($this->Participant->saveAll($this->request->data)) {
$this->Session->setFlash('Your registration was recorded. You will receive an email with further details during the next 24 hours.');
$this->Mail->sendConfirmEmail($this->Participant->findById($this->Participant->id));
$this->redirect(array(
'controller' => 'pages',
'action' => 'welcome'));
}
else {
$this->Session->setFlash('Your registration could not be completed. Please try again.');
}
}
}
}
如何获得创建函数来添加 id。DB似乎没有问题,因为您可以登录并在其他控制器上获取数据