There are two ways to add data, one is the array method, and the other is adding using AR. In fact, the adding methods of these two methods are the same, it is just a standard difference. The so-called AR is :
//A data model represents a table.
//An object represents a piece of data.
//A field represents an attribute of an object
This is also in line with traditional thinking habits. The following is the example code added for data simulation:
$temp=D('User'); // $arr=array('id'=>11,'name'=>'add_1_xuning','password'=>md5('123456')); //下面是通过AR的方式进行数据添加 //一个数据模型代表一张表。 //一个对象代表一条数据。 //一个字段代表一个对象的属性 $temp->name="add_xuning"; $temp->password=md5('456'); $res=$temp->add(); // $res=$temp->add($arr); if($res){ $info=$temp->select(); $this->assign('info',$info); $this->display(); }else{ echo "添加失败"; } }
1: {$smarty.const.__SELF__} represents the controller path of the current asking price.
2: There are three ways to collect data:
public function add_data(){ if(!empty($_POST)){ $arr=$_POST; $temp=D('User'); //$res=$temp->add($arr);//直接添加 // $temp->id=$_POST['id'];//AR添加 // $temp->name=$_POST['usename']; // $temp->password=md5($_POST['password']); $temp->create();//create添加 $res=$temp->add(); if($res){ echo "添加成功"; }else{ echo "添加失败"; } }else{ echo "内容为空"; $this->display(); } }
In this case, the addition of data is completed