您当前的位置: 首页 > 学无止境 > 网站建设 网站首页网站建设
thinkphp实战-curd演示
发布时间:2015-12-08 08:53:42编辑:雪饮阅读()
新增模块(控制器)
浏览器访问新增的模块user模块
可尝试省略最后的index,若仍然能够访问请总结。
使用新增模块进行数据的删除与修改
1、用户控制器中删除与修改方法:
2、数据删除与修改主模版:
3、数据修改模版:
修改界面的值已经全部传递过来了,具体修改下次见。
源代码
User控制器所有方法:
// 本类由系统自动生成,仅供测试用途
class UserAction extends Action {
public function index(){
$m=M("User");
$array=$m->select();
$this->assign('data',$array);
$this->display();
}
public function del(){
$m=M("User");
$id=$_GET["id"];
$count=$m->delete($id);
if($count>0){
$this->success("数据删除成功");
}
else{
$this->error("数据删除失败");
}
}
public function modify(){
$m=M("User");
$id=$_GET["id"];
$arr=$m->find($id);
$this->assign("data",$arr);
$this->display();
}
}
User控制器index模版:
<body>
<center>
<table border="1">
<tr>
<th>id</th>
<th>name</th>
<th>sex</th>
<th>操作</th>
</tr>
<volist name="data" id="vo">
<tr>
<td><{$vo.id}></td>
<td><{$vo.name}></td>
<td><{$vo.sex}></td>
<td><a href="/User/del/id/<{$vo.id}>">删除</a>|<a href="/User/modify/id/<{$vo.id}>">修改</a></td>
</tr>
</volist>
</table>
</center>
</body>
User控制器modify模版:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<script type="text/javascript">
window.onload=function(){
if(<{$data.sex}>==0){
document.getElementsByName("sex")[1].checked="checked";
}
else{
document.getElementsByName("sex")[0].checked="checked";
}
}
</script>
</head>
<body>
<form>
姓名:
<input type="text" name="username" id="username" value="<{$data.name}>"/><br/>
性别:
<input type="radio" name="sex" id="radio" value="1">男
<input type="radio" name="sex" id="radio2" value="0">女<br/>
<input type="submit" value="提交修改">
</form>
</body>
</html>
关键字词:thinkphp,curd,个人博客
下一篇:apache如何设置404页面