原文:ThinkPhp学习06
一、简单学习修改用户信息模块
1、编写UserAction.class.php
1 <?php 2 3 class UserAction extends Action{ 4 public function index(){ 5 $m=M(‘User‘); 6 $arr=$m->select(); 7 $this->assign(‘data‘,$arr); 8 $this->display(); 9 } 10 public function del(){ 11 $m=M(‘User‘); 12 $id=$_GET[‘id‘]; 13 $count=$m->delete($id); //删除获取到的id,成功返回执行条数,失败为0 14 if($count>0){ 15 $this->success("删除成功!"); //提示删除成功后返回 16 }else{ 17 $this->error("删除失败!"); //提示删除失败后返回 18 } 19 } 20 21 public function modify(){ 22 $m=M(‘User‘); 23 $id=$_GET[‘id‘]; //获取传入的id值 24 $arr=$m->find($id); 25 $this->assign(‘data‘,$arr); 26 $this->display(); 27 } 28 29 30 } 31 32 ?>
2、UserAction对应index方法的页面
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 5 <title>Insert title here</title> 6 </head> 7 <body> 8 <table border=‘1‘ width=‘400px‘ align=‘center‘> 9 <tr> 10 <th>Id</th> 11 <th>User</th> 12 <th>sex</th> 13 <th>操作</th> 14 </tr> 15 <volist name=‘data‘ id=‘vo‘> 16 <tr> 17 <td><{$vo.id}></td> 18 <td><{$vo.username}></td> 19 <td><{$vo.sex}></td> 20 <td><a href=‘/thinkphp/test/index.php/User/del/id/<{$vo.id}>‘>删除</a><a href=‘/thinkphp/test/index.php/User/modify/id/<{$vo.id}>‘>修改</a></td> 21 </tr> 22 23 </volist> 24 </table> 25 </body> 26 </html>
3、对应修改用户信息的页面
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script> window.onload=function(){ var sex=<{$data.sex}>; //根据传入的数值来选中性别 if(sex==1){ document.getElementsByName(‘sex‘)[0].checked="checked"; } else{ document.getElementsByName(‘sex‘)[1].checked="checked"; } } </script> <title>Insert title here</title> </head> <body> <form action=""> 姓名:<input type="text" name="username" value="<{$data.username}>" /><br/> 性别:男<input type="radio" name="sex" value="1" />女<input type="radio" name="sex" value="0" /><br/> <input type="submit" value="提交" /> </form> </body> </html>
时间: 2024-10-07 12:26:42