我是cakephp 3中的新手.我想用多个复选框保存多个记录.我在事件表中有一些事件,在密码表中有一些密码.我想在每个事件下设置不同的密码.例如 - 对于事件1,我想设置一些密码,这些密码将存储在event_password_all表中.
(id,event1,password1),(id,event1,password2),(id,event1,password3),......(id,event1,passwordN)
我怎样才能做到这一点.
这是我的控制器代码 -
public function add()
{
$eventPasswordAll = $this->EventPasswordAll->newEntity();
if ($this->request->is('post')) {
$eventPasswordAll = $this->EventPasswordAll->patchEntity($eventPasswordAll, $this->request->data);
if ($this->EventPasswordAll->save($eventPasswordAll)) {
$this->Flash->success(__('The event password all has been saved.'));
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error(__('The event password all could not be saved. Please, try again.'));
}
}
$events = $this->EventPasswordAll->Events->find('list', ['limit' => 200]);
$passwords = $this->EventPasswordAll->Passwords->find('list', ['limit' => 200]);
$this->set(compact('eventPasswordAll', 'events', 'passwords'));
$this->set('_serialize', ['eventPasswordAll']);
}
Run Code Online (Sandbox Code Playgroud)
这是观点 -
<div class="eventPasswordAll form large-10 medium-9 columns">
<?= $this->Form->create($eventPasswordAll) …Run Code Online (Sandbox Code Playgroud)