ThinkPHP中自動驗證失敗

來源:互聯網
上載者:User

標籤:style   color   使用   io   檔案   資料   問題   cti   

本人最近剛開始學ThinkPHP,在練習的過程中遇到了一些問題。下面是我在進行TP自動驗證時遇到的問題!

表名是test_member

Controller代碼如下:

<?phpnamespace Regiter\Controller;use Think\Controller;class IndexController extends Controller {    public function index(){        $this->display();    }    public function register($email="",$password="",$cpassword=‘‘,$name="",$phone="",$address=""){        $rdata = array(‘email‘=>$email,‘password‘=>$password,‘name‘=>$name,‘phone‘=>$phone,‘adress‘=>$address);        $User = D("Member");        if (!$User->create($rdata)){            // 如果建立失敗 表示驗證沒有通過 輸出錯誤提示資訊            $this->ajaxReturn($User->getError());        }else{            //$User->add($rdata);            $this->success($User->select());            // 驗證通過 可以進行其他資料操作        }    }}

Model代碼如下:

<?php/** * Created by PhpStorm. * User: BaByDragon * Date: 14-8-1 * Time: 下午2:48 */namespace Regiter\Model;use Think\Model;class MemberModel extends Model{    protected $tableName = ‘member‘;    protected $_validate = array(        array(‘email‘,‘require‘,‘驗證碼必須!‘),  // 都有時間都驗證        array(‘name‘,‘‘,‘帳號名稱已經存在!‘,0,‘unique‘,1),        array(‘name‘,‘checkName‘,‘帳號錯誤!‘,1,‘function‘,4),  // 只在登入時候驗證        array(‘password‘,‘checkPwd‘,‘密碼錯誤!‘,1,‘function‘,4), // 只在登入時候驗證    );}?>

結果自動驗證怎麼也不成功!最後發現Model檔案名稱錯了!TP模型層的檔案名稱應是表名(駝峰法命名,並且首字母大寫)+.class.php。而我卻寫成了表名+.php。

通過本次教訓我總結了TP中使用自動驗證時許注意:D方法的參數是Model的名字而不是表的名字!


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.