User模块的方法;
public function search(){
var_dump($_POST);
}
<!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>
function jump(){
window.location="http://localhost:8080/thinkphp/index.php/User/add";
}
</script>
</head>
<body>
<form action='/thinkphp/index.php/User/search' method='post'>
用户名:<input type='text' name='username'/>
性别:<input type='radio' name='sex' value='1'/>男<input type='radio' name='sex' value='0'/>女
<input type='submit' value='搜素'/>
</form>
<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>|<a href="http://localhost:8080/thinkphp/index.php/User/modify/id/<{$vo.id}>">修改</a></td>
</tr>
</volist>
</table>
<center>
<button οnclick="jump()">添加用户</button>
</center>
</body>
</html>
<form action='/thinkphp/index.php/User/search' method='post'>
form表单的动作是 调用/thinkphp/index.php/User/search
public function search(){
var_dump($_POST);
}
打印出的内容:
array (size=2)
'username' => string 'xxyy' (length=4)
'sex' => string '1' (length=1)
public function search(){
var_dump($_POST);
// 获取POSTT的数据,根据数据组查询的条件,根据条件从数据库中获取数,
//返回给页面遍历
把数据分配给前台模板,去找index的前台模板
$m=M('user');
if
$where['username']=$_POST['username']
$where['sex']=$_POST['sex']
$arr=$m->where($where)->select()
$this->assign('data',$arr);
$this->display('index');
}
组装的SQL:
SELECT * FROM `user` WHERE ( `username` = 'xxyy' ) AND ( `sex` = '0' ) [ RunTime:0.015743s ]
$m=M('user');
if (isset($_POST['username'])){
$where['username']=$_POST['username'];
};
if (isset($_POST['sex'])){
$where['sex']=$_POST['sex'];
};
#$where['logic']
echo $where['username'];
echo $where['sex'];
$arr=$m->where($where)->select();
$this->assign('data',$arr);
$this->display('index');
}
$m=M('user');
if (isset($_POST['username']) && $_POST['username'] !=null ){
$where['username']=$_POST['username'];
};
if (isset($_POST['sex']) && $_POST['sex'] !=null){
$where['sex']=$_POST['sex'];
};
#$where['logic']
echo $where['username'];
echo $where['sex'];
$arr=$m->where($where)->select();
$this->assign('data',$arr);
$this->display('index');
}
等价于;
<form action='/thinkphp/index.php/User/search' method='post'>
<form action='__URL__/search' method='post'>