<?php class FormAction extends Action{ public function insert(){ $Form=D('think_form'); if($Form->create()) { $result =$Form->add(); if($result) { $this->success('操作成功!'); }else{ $this->error('写入错误!'); } }else{ $this->error($Form->getError()); } } public function read($id=5){ $Form=M("think_form"); $data=$Form->find($id); if ($data) { $this->data=$data; }else{ $this->error("数据错误"); } $this->display(); } public function edit($id=0){ $Form=M("think_form"); $this->vo=$Form->find($id); $this->display(); } public function update(){ $Form=D("think_form"); if ($Form->create()) { $result=$Form->save(); if ($result) { $this->success("操作成功!"); }else{ $this->error("写入错误!"); } }else{ $this->error($Form->getError()); } } } ?>
add html文件:
<FORM method="post" action="__URL__/insert"> 标题:<INPUT type="text" name="title"><br/> 内容:<TEXTAREA name="content" rows="5" cols="45"></TEXTAREA><br/> <INPUT type="submit" value="提交"> </FORM>
read文件:
<!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8"> <title></title> </head> <body> <table> <tr> <td>id:</td> <td>{$data.id}</td> </tr> <tr> <td>标题:</td> <td>{$data.title}</td> </tr> <tr> <td>内容:</td> <td>{$data.content}</td> </tr> </table> </body> </html>
edit文件:
<!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8"> <title></title> </head> <body> <FORM method="post" action="__URL__/update"> 标题:<INPUT type="text" name="title" value="{$vo.title}"><br/> 内容:<TEXTAREA name="content" rows="5" cols="45">{$vo.content}</TEXTAREA><br/> <INPUT type="hidden" name="id" value="{$vo.id}"> <INPUT type="submit" value="提交"> </FORM> </body> </html>