我做出laravel 4.2自定義驗證的自定義驗證指定的,並把在應用程序不能識別的錯誤信息/開始/ global.php和我的代碼有這個在laravel 4.2
Validator::extend('captcha', function($attribute, $value, $parameters)
{
$captcha = $_SESSION["captcha"];
return $value == $captcha;
});
Validator::extend('cSY', function($attribute, $value, $parameters)
{
$appnd = "SY " . $value ."-". ($value + 1);
$chkSY = DB::table('dbo_schoolyear')
->where('SchoolYear' , '=' , $appnd)
->count();
if($chkSY)
{
return false;
}
else
{
return true;
}
});
然後在我控制器這裏是我的代碼
$rules = array(
'nsy' => 'required|integer|min:2005|cSY'
);
$messages = array(
'nsy.required' => 'Please enter Starting Year.',
'nsy.integer' => 'Starting year can only contain integer values',
'nsy.min' => 'School Year Minimum is 2005',
'nsy.cSY' => 'School Year exists'
);
驗證工作正常,但我在郵件數組中聲明的消息未被識別。我不知道爲什麼。它輸出的錯誤是validation.c_sy關於我在做什麼錯誤的任何想法?
作爲一個瘋狂的猜測我懷疑camelCase問題。嘗試將'cSY'改爲'csy'。 – Adrenaxus
謝謝!我工作了! :)請把這個答案:) – BourneShady
我很高興我瘋狂的猜測是正確的。乾杯! – Adrenaxus