在cakephp中将表单数据插入数据库

在cakephp中将表单数据插入数据库,cakephp,cakephp-3.0,cakephp-2.3,Cakephp,Cakephp 3.0,Cakephp 2.3,我想使用cakephp将表单数据插入数据库。我在layouts文件夹中创建了form.ctp文件。现在如何将表单值插入form.ctp文件中的数据库 这是我的密码: <html> <form action="../users/register" method="post"> <p>Please fill out the form below to register an account.</p> <label>Username:<

我想使用cakephp将表单数据插入数据库。我在layouts文件夹中创建了form.ctp文件。现在如何将表单值插入form.ctp文件中的数据库

这是我的密码:

<html>
<form action="../users/register" method="post">
<p>Please fill out the form below to register an account.</p>
<label>Username:</label><input name="username" size="40" />
<label>Password:</label><input type="password" name="password" size="40"
/>
<label>Email Address:</label><input name="email" size="40"
maxlength="255" />
<label>First Name:</label><input name="first_name" size="40" />
<label>Last Name:</label><input name="last_name" size="40" />
<input type="submit" value="register" />
</form>
</html>
或 通过以下方式保存数据而不更改表单

if ($this->request->is('post')) { 
    $this->request->data['User'] = $this->request->data;
    $this->User->save($this->request->data);
}

遵循CakePHP文档,您将了解这一点。逻辑将在您的方法中处理。
if ($this->request->is('post')) { 
    $this->User->save($this->request->data);
}
if ($this->request->is('post')) { 
    $this->request->data['User'] = $this->request->data;
    $this->User->save($this->request->data);
}