MainController.class.php
function Add() { if(empty($_POST)) { $this->display(); } else { $model = D("Info"); //添加数据的第一种方式,数组添加 //要添加的数组,必须是关联数组,key必须为字段名称,大小写区分 $attr = array( 'Code'=>'p100', 'Name'=>'护甲', 'Sex'=>'true', 'Nation'=>'n002', 'Bierhday'=>'1999-1-2' ); $attr["Code"] = "p112"; $attr["Name"] = "啊哈"; $attr["Sex"] = "false"; $attr["Nation"] = "n003"; $attr["Birthday"] = "1435-5-12"; $model->add($attr);//添加数据的方法,需要参数,该参数是一个关联数组 二:AR方式 1.连接类 2.实体类 3.数据访问类 $model->Code = "p122"; $model->Name = "操作"; $model->Sex = "true"; $model->Nation = "n001"; $model->Birthday = "1657-2-1"; $model->add(); 三:自动收集表单 $model->create();//自动收集表单并且创建数据 $_POST["Sex"]=="男"?true:false; $z = $model->add(); if($z) { $this->success("添加数据成功!","Add",5); //添加成功五秒后返回 } else { $this->error("添加失败!","Add",5); } } }
Add.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<form action="__ACTION__" method="post">
<div>代号:<input type="text" name="Code" /></div>
<div>姓名:<input type="text" name="Name" /></div>
<div>性别:<input type="text" name="Sex" /></div>
<div>民族:<input type="text" name="Nation" /></div>
<div>生日:<input type="text" name="Birthday" /></div>
<input type="submit" value="添加" />
</form>
</body>
</html>