1 回答

TA贡献1862条经验 获得超6个赞
要获取发布数据,请使用调试
debug($this->request->getData());
看起来您需要所有 CRUD 代码。
因此,您可以在下面创建您的用户 add.ctp 文件
位置:模板\用户\add.ctp
<?= $this->Form->create($user) ?>
<?php
echo $this->Form->control('username');
echo $this->Form->control('email');
echo $this->Form->control('password');
?>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>
然后用户控制器看起来像
UsersController/add method look like
public function add()
{
$user = $this->Users->newEmptyEntity();
if ($this->request->is('post')) {
$user = $this->Users->patchEntity($user, $this->request->getData());
if ($this->Users->save($user)) {
$this->Flash->success(__('The user has been saved.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('The user could not be saved. Please, try again.'));
}
$this->set(compact('user'));
}
你需要更多吗?只需要在你的应用文件夹中给出一个简单的命令来生成你的 CRUD。
发号施令
bin/cake bake all users
假设,users 是你的数据库表名。然后你会得到添加,编辑,删除,查看。 可以看这个教程看看如何给蛋糕烘烤命令
- 1 回答
- 0 关注
- 92 浏览
添加回答
举报