我在做cakephp3。在面包店之后,例如用户表,添加动作,在我的项目中,id(primarykey)应由用户填充,蛋糕不会向用户显示id(primarykey)。我使用echo $this->Form->input('id',['type' => 'number']);
,但id没有插入数据库。
如何按用户添加主键?
add.ctp
<?= $this->Form->create($user) ?>
<fieldset>
<?php
echo $this->Form->input('id',['type' => 'number']);
echo $this->Form->input('name');
echo $this->Form->input('password');
?>
</fieldset>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>
功能添加()
public function add() {
$user = $this->Users->newEntity();
if ($this->request->is('post')) {
$user = $this->Users->patchEntity($user, $this->request->data);
if ($this->Users->save($user)) {
$this->Flash->success(__('The user has been saved.'));
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error(__('The user could not be saved. Please, try again.'));
}
}
$roles = $this->Users->Roles->find('list', ['limit' => 200]);
$dormitories = $this->Users->Dormitories->find('list', ['limit' => 200]);
$this->set(compact('user', 'roles', 'dormitories'));
$this->set('_serialize', ['user']);
}