classIndexactionextendsAction {//Querying Data Public functionindex () {$Form= M ("Form"); $list=$Form->limit (3)->order (' id desc ')Select (); $this-List=$list; $this-display (); } //Write Data Public functionInsert () {$Form= D ("Form"); if($vo=$Form-Create ()) { $list=$Form-Add (); if($list!==false) { $this->success (' Data saved successfully! ', U (' Index/index ')); } Else { $this->error (' Data write Error! ‘); } } Else { $this->error ($Form-GetError ()); } } //Update Data Public functionUpdate () {$Form= D ("Form"); if($vo=$Form-Create ()) { $list=$Form-Save (); if($list!==false) { $this->success (' Data update succeeded! ', U (' Index/index ')); } Else { $this->error ("No data Updated!")); } } Else { $this->error ($Form-GetError ()); } } //Delete Data Public functionDelete$id) { if(!Empty($id)) { $Form= M ("Form"); $result=$Form->delete ($id); if(false!==$result) { $this->success (' Delete succeeded! ‘); } Else { $this->error (' Delete error! ‘); } } Else { $this->error (' ID error! ‘); } } //Edit Data Public functionEdit$id) { if(!Empty($id)) { $Form= M ("Form"); $vo=$Form->getbyid ($id); if($vo) { $this->vo =$vo; $this-display (); } Else { $this->error (' data does not exist! ‘); } } Else { $this->error (' data does not exist! ‘); } } }
thinkphp crud Instance Code