Thinkphp添加自動驗證規則後無法寫入資料庫也沒有任何報錯資訊,怎麼回事?

來源:互聯網
上載者:User
只要添加UserModel.class.php就不能提交資料到資料庫,而且沒有任何提示,表單頁面也沒有任何提交成功或者失敗的提示。
代碼如下:(Thinkphp 3.2)
接收表單的控制器的代碼:

display();                 $user=D("User");//自動驗證並沒有實現,為什嗎?        if($user->create()){            if($user->add()){$this->success("註冊成功,頁面正在跳轉...");}            else{$user->getError();}        }else{$user->getError();}        }         } 

UserModel.class.php中的代碼 :

"psd",//資料庫中用的是psd欄位        );    protected $_validate = array(         //array(驗證欄位1,驗證規則,錯誤提示,[驗證條件,附加規則,驗證時間]),         array("uname","require","使用者名稱不可為空",1),         array("uname","/^\w{3,16}$/","使用者名稱必須由3-16位的數字字母底線組成",1,"regex"),         array("uname","","使用者名稱已經存在",1,"unique"),         array("pwd1","require","密碼不可為空"),         array('pwd1', '/^\w{6,20}$/s',"密碼格式不正確",1,"regex"),         array('pwd2', 'password', '兩次密碼不一致', 1, 'confirm'),         array("email","email","郵箱格式不正確性",1),         array("email","","郵箱登入,請換一個郵箱","unique")        );    //自動完成    protected $_auto = array(        array('pwd2', 'md5', 3, 'function')        );}

回複內容:

只要添加UserModel.class.php就不能提交資料到資料庫,而且沒有任何提示,表單頁面也沒有任何提交成功或者失敗的提示。
代碼如下:(Thinkphp 3.2)
接收表單的控制器的代碼:

display();                 $user=D("User");//自動驗證並沒有實現,為什嗎?        if($user->create()){            if($user->add()){$this->success("註冊成功,頁面正在跳轉...");}            else{$user->getError();}        }else{$user->getError();}        }         } 

UserModel.class.php中的代碼 :

"psd",//資料庫中用的是psd欄位        );    protected $_validate = array(         //array(驗證欄位1,驗證規則,錯誤提示,[驗證條件,附加規則,驗證時間]),         array("uname","require","使用者名稱不可為空",1),         array("uname","/^\w{3,16}$/","使用者名稱必須由3-16位的數字字母底線組成",1,"regex"),         array("uname","","使用者名稱已經存在",1,"unique"),         array("pwd1","require","密碼不可為空"),         array('pwd1', '/^\w{6,20}$/s',"密碼格式不正確",1,"regex"),         array('pwd2', 'password', '兩次密碼不一致', 1, 'confirm'),         array("email","email","郵箱格式不正確性",1),         array("email","","郵箱登入,請換一個郵箱","unique")        );    //自動完成    protected $_auto = array(        array('pwd2', 'md5', 3, 'function')        );}

 $user=D("user");//自動驗證並沒有實現,為什嗎? 

D("User") 試試 ,注意D方法執行個體化的時候的模型名稱的大小寫.

與資料庫中的大小寫要一致哦

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.