1 //数据修改
2 function Update()
3 {
4 $model = D("info");
5
6 /*
7 //1,数组方式
8 $attr = array(
9 "Code"=>"p001",
10 "Name"=>"张三",
11 "Sex"=>true,
12 "Nation"=>"n001",
13 "Birthday"=>"1998-3-2"
14 );
15
16 //调用save方法来修改数据
17 $model->save($attr);
18 */
19
20 /*
21 //2,AR方式
22 $model->Name="王五";
23 $model->Nation="n003";
24
25 $model->where("Code = ‘p0012‘")->save();
26 */
27
28 //3,自动收集表单
29 if(empty($_POST))
30 {
31 $code = "p002";
32 $attr = $model->find($code);
33 $this->assign("shuju",$attr);
34
35 $this->display();
36 }
37 else
38 {
39 $model->create();
40 $model->save();
41 }
42
43 }
//数据删除
function Delete()
{
//删除数据
$model = D("info");
//根据主键值删除
$model->delete("p0012");
//根据条件删除
$model->where("Name=‘CJKE‘")->delete();
}
1 //显示所有数据的方法
2 function ShowInfo()
3 {
4 $model = D("Info");
5 $attr = $model->field("Info.Code as InfoCode,Info.Name as InfoName,Info.Sex,
Nation.Name as NationName,Info.Birthday")->join("Nation on Info.Nation=Nation.Code")->select();
6 $this->assign("shuju",$attr);
7 $this->display();
8 }
1 <body>
2 <h1>主页面h1>
3
4 <table border="1" width="100%" cellpadding="0" cellspacing="0">
5 <tr>
6 <td>代号td>
7 <td>姓名td>
8 <td>性别td>
9 <td>民族td>
10 <td>生日td>
11 <td>操作td>
12 tr>
13
14 <foreach name="shuju" item="v">
15 <tr>
16 <td><{$v.infocode}>td>
17 <td><{$v.infoname}>td>
18 <td><{$v["sex"]=="1"?"男":"女"}>td>
19 <td><{$v.nationname}>td>
20 <td><{$v.birthday}>td>
21 <td>
22 <a href="__CONTROLLER__/XiuGai/code/<{$v.infocode}>" >修改a>
23 <a href="__CONTROLLER__/ShanChu/code/<{$v.infocode}>">删除a>
24 td>
25 tr>
26 foreach>
27
28 table>
29
30 body>
31 html>