死活死活 插入数据为控制! 请教?
thinkphp吧
全部回复
仅看楼主
level 1
乞丐有形 楼主
如题:
UserAction.class.php
<?php
// 本类由系统自动生成,仅供测试用途
class UserAction extends Action {
public function index() {
}
public function add() {
$this->display();
}
public function insert() {
$user = new UserModel();
if ($data = $user->create()) {
if (FALSE !== $user->add()) {
$userid = $user->getLastInsID();
echo "创建成功!" . $userid;
} else {
echo "创建失败" . $user->getDbError();
}
} else {
echo $user->getError();
}
}
}
?>

2012年07月27日 06点07分 1
level 1
乞丐有形 楼主
UserModel.class.php
<?php
class UserModel extends Model {
protected $_validate = array(
array('uname', 'require', '用户账号必须填写', 1, 'regex', 3), //regex 正则验证require 字段必须
// array('uname', 'require', '用户账号已存在'), //是否唯一
array('pwd', 'require', '密码必须填写'),
array('email', 'email', '邮箱格式错误'),
array('active', array(0, 1), '数据错误', 0, 'in'),
array('pwd', 'checkpwd', '密码长度不够六位', 1, 'function'),
);
protected $_mpa=array(
'pwd'=>'password',
'uname'=>'username',
);
protected $_auto=array(
array('reg_date','getDate',1,'callback'),
array('password','md5',1,'function'),
);
function getDate(){
return date("Y-m-d H:i:s");
}
};
?>

2012年07月27日 06点07分 2
level 1
乞丐有形 楼主

2.0 版本
插入数据为空值!
2012年07月27日 06点07分 3
1