Home > Backend Development > PHP Tutorial > 关于用thinkphp会员登录的表单自动验证的问题?

关于用thinkphp会员登录的表单自动验证的问题?

WBOY
Release: 2016-06-23 14:18:28
Original
1069 people have browsed it

我的MemberAction代码是

<?phpclass 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());        }    } }?>
Copy after login


我的MemberModel代码是
<?phpclass 	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'),     );   }?>
Copy after login


问题是它不自动验证,不管你填什么都能注册成功,不填的话就是注册失败,不知道怎么回事,请教各位大大


回复讨论(解决方案)

$Member   =   D('developers');   不存在自定义模型类delelopers,所以实例化的是Model基类。所以你MemberModel 的验证没有生效。

$Member   =   D('developers');   不存在自定义模型类delelopers,所以实例化的是Model基类。所以你MemberModel 的验证没有生效。
那应该怎么改呢?

$Member   =   D('Member');

$Member   =   D('Member');

是的 我改了 但是我的数据表是developers,这样是自动验证了,但是没有想数据库添加上注册的内容啊,那该怎么办?

MemberModel里加上 :   protected $tableName = 'developers'; 

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template