要向Laravel添加新验证,我已经这样做了:
做了一个所谓的新文件customValidation.php
中app/start/
然后把它包括进来app/start/global.php
并用echo()
它测试它并且它起作用了.所以它现在被加载到应用程序中.
然后我编写了以下代码来验证Laravel中的复选框:
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ class customValidate extends Illuminate\Validation\Validator { public function validateCheckbox($attribute, $value, $parameters) { //if(isset($value)) { return true; } else { return true; } echo "this is the: " . $value; } } /** * Resolvers for Custom Validations */ Validator::resolver(function($translator, $data, $rules, $message){ return new customValidate($translator, $data, $rules, $message); });
但是,在我的验证规则中,我定义:
`array('sex'=>'checkbox')`
但它不起作用.什么都没发生.不会抛出任何错误.该应用程序的行为就像它根本没有执行该功能一样.此外,当我从函数内部回显一些东西时,没有任何东西得到回应,这是函数根本没有被调用的另一个证据.