本节课大纲:
一、ThinkPHP 3 的CURD管理用户信息
http://localhost:8080/thinkphp/index.php/User/index
访问User类的index方法
模板不存在[./Home/Tpl/User/index.html]
需要模板文件
C:wampwww hinkphpHomeTplUser
模块名方法.html
html 页面遍历数组;
<volist name='data'>
必须有name 属性 ,属性值为data
<volist name='data' id='vo'>
必须有id属性,属性值随便取 比如vo
/* 读取数据插入表格
<!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>
</head>
<body>
<h1>scan show 你好 hhhello world</h1>
<table border='1' width='500' align='center'>
<tr>
<th>id</th>
<th>username</th>
<th>sex</th>
<th>操作</th>
</tr>
<volist name='data' id='vo'>
<tr>
<td><{$vo.id}></td>
<td><{$vo.username}></td>
<td><{$vo.sex}></td>
<td>删除|修改</td>
</tr>
</volist>
</table>
</body>
</html>
/**删除数据
public function del(){
$m=M('user');
##删除具体id数据
$id=$_GET['id'];
$count=$m->delete($id);
echo $count;
if ($count>0){
$this->success('数据删除成功');
}else{
$this->error('数据删除失败');
}
}
}
对应的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>
</head>
<body>
<h1>scan show 你好 hhhello world</h1>
<table border='1' width='500' align='center'>
<tr>
<th>id</th>
<th>username</th>
<th>sex</th>
<th>操作</th>
</tr>
<volist name='data' id='vo'>
<tr>
<td><{$vo.id}></td>
<td><{$vo.username}></td>
<td><{$vo.sex}></td>
<td><a href="http://localhost:8080/thinkphp/index.php/User/del/id/<{$vo.id}>">删除</a>|修改</td>
</tr>
</volist>
</table>
</body>
</html>
/*修改操作
thinkphp 所有的操作都是控制器(方法来完成)
<volist name='data' id='vo'>
<tr>
<td><{$vo.id}></td>
<td><{$vo.username}></td>
<td><{$vo.sex}></td>
<td><a href="http://localhost:8080/thinkphp/index.php/User/del/id/<{$vo.id}>">删除</a>|<a href="http://localhost:8080/thinkphp/index.php/User/modify/id/<{$vo.id}>">修改</a></td>
</tr>
</volist>
</table>
</body>
</html>
这里超链接到一个url ,后台获取url传入的参数
//负责修改页面 ,获取get请求传入的id
public function modify(){
$id=$_GET['id'];
$m=M('user');
$arr=$m->find($id);
$this->assign('data',$arr);
$this->display();
}
把值传给前台
<!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>
</head>
<body>
<form>
姓名:<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='提交修改'/></br>
</form>
</body>
</html>