我正在基于数据库CRUD操作基于CakePhp
开发一个简单的应用程序。
更新(编辑)按钮无法正常工作。
控制器编辑功能:
function edit($id = null) {
$this->User->id = $id;
if (empty($this->data))
{
$this->data = $this->User->read();
}
else
{
if ($this->User->save($this->data))
{
$this->flash('Your user with id: '.$id.' has been updated.','/users/read');
//$this->redirect(array('action' => 'read'));
}
}
}
edit.ctp:
<h1>Edit User</h1>
<!--?php
echo $this--->Form->create('User', array('action' => 'edit'));
echo $this->Form->input('id', array('type'=>'hidden'));
echo $this->Form->input('first_name');
echo $this->Form->input('last_name');
echo $this->Form->input('email');
echo $this->Form->input('mobile');
echo $this->Form->end('Update User');
?>
uesr.php
<?php
class User extends AppModel
{
var $name='User';
?>
这里的问题是当我输入编辑表单时数据不会提交。
答案 0 :(得分:0)
这里我假设你已经注册了一个用户和用户$ id = 13;
<强>被修改强> __users_controller.php __
function edit($id = null) {
if (empty($this->data))
{
$this->data = $this->User->read(null, $id);
}
else
{
$this->User->id = $id;
if ($this->User->save($this->data))
{
$this->flash('Your user with id: '.$id.' has been updated.','/users/read');
//$this->redirect(array('action' => 'read'));
}
}
}
<强> edit.ctp 强>
<?php
echo $this->Form->create('User', array('action' => 'edit'));
echo $this->Form->input('first_name');
echo $this->Form->input('last_name');
echo $this->Form->input('email');
echo $this->Form->input('mobile');
echo $this->Form->end('Update User');
?>
然后尝试网址localhost/project/UserRegisterForm/users/edit/13
在这里,我假设您已经注册了一个用户和用户$ id = 13;