?? ?? ?? ? ??
??? ??????? ??? ???? ???? ??? TP5? ?? ????? ??? ??????. ??? application/index/model/User.php ??? ????? ?? ???.
??
<?php namespace app\index\model; use think\Model; class User extends Model { protected $pk = 'user_id'; }
By ?? ???? ?? ?? ??? ??? ??? ????.
<form action="/public/index.php/index/regist/regist" method="post">
???? ?????? ?? /index/controller/Regist.php
?? ??? ??:
<?php //用戶注冊(cè) public function regist(){ //實(shí)例化User $user = new User; //接收前端表單提交的數(shù)據(jù) $user->user_name = input('post.UserName'); $user->user_sex = input('post.UserSex'); $user->user_tel = input('post.UserTel'); $user->user_email = input('post.UserEmail'); $user->user_address = input('post.UserAddress'); $user->user_birth = input('post.UserBirth'); $user->user_passwd = input('post.UserPasswd'); $user->user_signature = input('post.UserSignature'); $user->user_hobby = input('post.UserHobby'); //進(jìn)行規(guī)則驗(yàn)證 $result = $this->validate( [ 'name' => $user->user_name, 'email' => $user->user_email, 'sex' => $user->user_sex, 'tel' => $user->user_tel, 'address' => $user->user_address, 'birth' => $user->user_birth, 'password' => $user->user_passwd, ], [ 'name' => 'require|max:10', 'email' => 'email', 'sex' => 'number|between:0,1', 'tel' => 'require', 'address' => 'require', 'birth' => 'require', 'password' => 'require', ]); if (true !== $result) { $this->error($result); } //寫入數(shù)據(jù)庫 if ($user->save()) { return $this->success('注冊(cè)成功'); } else { return $this->success('注冊(cè)失敗'); } }
$result? ?? ??? ??? ???? true? ????. .??? ?? ?? ?? ??? ??? ?? ???? ?????
??('post.UserName')?? ?? ?? (?? ??)(??? nama ? ??)
? ???? ???.
??? ?? ?? ??? ?????
??? ??? ????.
??????? ??? ?? ?????.