关于用thinkphp会员登录的表单自动验证的问题?
我的MemberAction代码是
<?php
class MemberAction extends Action{
public function insert()
{
header('Content-Type:text/html; charset=utf-8');
$Member = D('developers');
if($Member->create()) {
$result = $Member->add();
if($result) {
$this->success('注册成功!');
}else{
$this->error('注册失败!');
}
}else{
$this->error($Member->getError());
}
}
}
?>
<?php
class MemberModel extends Model {
protected $_validate = array(
array("username","require","用户名不能为空"),
array('username','','帐号名称已经存在!',0,'unique',1),
array("username","checkLength","用户名长度不符合要求",0,'callback'),
array('name','require','名字必须'),
array("password","require","密码不能为空"),
array("password","checkLength","密码长度的要求是5~15位之间",0,'callback'),
array('repassword','password','两次密码输入不一致',0,'confirm'),
);
protected $_auto = array(
array('status', '1', self::MODEL_INSERT),
array('create_time', 'time', self::MODEL_INSERT, 'function'),
);
}
?>
[解决办法]
$Member = D('developers'); 不存在自定义模型类delelopers,所以实例化的是Model基类。所以你MemberModel 的验证没有生效。
[解决办法]
$Member = D('Member');
[解决办法]
MemberModel里加上 : protected $tableName = 'developers';