public function modify(){
$id=$_GET['id'];
$m=M('user');
$arr=$m->find($id);
//var_dump($arr);
$this->assign('data',$arr);
$this->display();
}
modify 方法:
对应的前台模板:
E: hinkphpThinkPHP视频教程7.ThinkPHP 3.1.2 CURD演示 2 hinkphpHomeTplUsermodify.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus?">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
<script>
window.οnlοad=function(){
//alert ("<{$data.sex}>");
}
</script>
</head>
<body>
<form action="/thinkphp/index.php/User/update" method='post'>
<input type='hidden' name='id' value="<{$data.id}>">
姓名:<input type="text" name='username' value="<{$data.username}>"/><br/>
性别:男<input type='radio' name='sex' value='1' checked >女<input type='radio'
name='sex' value='0'/><br/>
<input type="submit" value="提交修改"/>
</form>
</body>
</html>
modify.html 又调用 /thinkphp/index.php/User/update 方法:
public function update(){
$id=$_GET['id'];
$m=M('user');
$data['id']=$_POST['id'];
$data['username']=$_POST['username'];
$data['sex']=$_POST['sex'];
$arr=$m->Save($id);
$count=$m->save($data);
//success 方法会调回到上一个页面
if($count >0){$this->success('数据修改成功','index');}
else{$this->error('数据修改失败','index');}
//var_dump($arr);
// $this->assign('data',$arr);
// $this->display();
}