FormController.class.php
<?php
namespace Home\Controller;
use Think\Controller;
class FormController extends Controller{
public function insert(){
$Form = D(‘Form‘);
if($Form->create()) {
$result = $Form->add();
// if($result) {
// $this->success(‘数据添加成功!‘);
// }else{
// $this->error(‘数据添加错误!‘);
// }
// }else{
// $this->error($Form->getError());
echo "ok!",$result;
}else{
echo "no!",$Form->getError(),"hh--$result";
}
}
}
Form/add.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body>
<div class="myform">
<form method="post" action="insert">
标题:<input name="title" type="text" /><br/>
内容:<textarea name="content" rows="5" cols="45"></textarea><br/>
<input type="submit" value="提交" />
</form>
</div>
</body>
</html>
FormModel.class.php(D函数需要有对应的模型类)
<?php
namespace Home\Model;
use Think\Model;
class FormModel extends Model {
//
定义自动验证
protected $_validate = array(
array(‘title‘,‘require‘,‘标题必须‘),
);
//
定义自动完成
protected $_auto = array(
array(‘create_time‘,‘time‘,1,‘function‘),
);
}
thinkphp笔记-创建数据2
原文:http://www.cnblogs.com/afra/p/5004920.html