學習thinkphp5 0驗證類使用方法

2022-10-06 06:33:14 字數 880 閱讀 8535

通過乙個例項,給大家講解一下如果通過thinkphp5.0驗證類的方法。

自定義驗證類,需繼承validate類

比如在home模組新建validate資料夾,再新建test.php驗證類,內容如下:

<?php namespace app\home\validate;

use think\validate;

class test extends validate

/', 'age' => 'number|between:1,120',

'email' => 'email'

];protected $message = [

'name.require' => 'name不能少',

'name.regex' =& 'name不能少於6個字元',

'age.number' => 'age必須是數字',

'age.between' => 'age必須在1到120之間',

'email.email' => 'email格式不對',

];protected $scene = [

'name_email' => ['name','email'],

]wwnepjlwh;

}?>

在index控制器test方法使用

<?php namespace app\home\controller;

use think\loader;

use think\controller;

class index extends controller

}}以上就是我們給出的驗證類的例項方法,如果還有**不明白,大家可以在下方留言一起討論。

本文標題: 學習thinkphp5.0驗證類使用方法

本文位址:

ThinkPHP5 0 接觸學習

mvc不是設計模式,而是設計典範。composer 是 php5.3以上 的乙個依賴管理工具。它允許你宣告專案所依賴的 庫,它會在你的專案中為你安裝他們。開發環境介紹 php版本 5.4.0 pdo mbstring curl php extension 安裝好這個擴充套件,thinkphp5能正常...

thinkphp5 0驗證碼使用

如果沒有安裝驗證碼類,可在composer.json 檔案的require裡面新增 topthink think captcha 1.然後composer update即可 thinkphp5.0內建驗證碼 頁面呼叫方式 將驗證碼通過表單提交到控制器方法執行以下 測試 code input capt...

ThinkPHP5 0學習 URL訪問

tp5支援path info和相容模式 示例 created by phpstorm.user wybing date 2019 7 16 time 14 13 class manager 通過path info方式訪問 通過相容模式方式訪問 輸入 推薦path info方式 url大小寫問題 1....