Last active
December 16, 2015 18:48
-
-
Save ackintosh/5479927 to your computer and use it in GitHub Desktop.
custom validation rule for fuelPHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* fuel/app/classes/myvalidations.php */ | |
class MyValidations | |
{ | |
// Method name must start at '_validation_' | |
public static function _validation_something_check($value) | |
{ | |
return $value ? true : false; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* fuel/app/tests/myvalidations.php */ | |
/** | |
* MyValidations class Tests | |
* | |
* @group App | |
*/ | |
class Test_MyValidations extends TestCase | |
{ | |
public function test_validation_something_check_valid() | |
{ | |
$input = 1; | |
$result = MyValidations::_validation_something_check($input); | |
$expect = true; | |
$this->assertEquals($expected, $test); | |
} | |
public function test_validation_something_check_invalid() | |
{ | |
$input = 0; | |
$result = MyValidations::_validation_something_check($input); | |
$expect = false; | |
$this->assertEquals($expected, $test); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$validation = Validation::forge(); | |
$validation->add_callable('MyValidations');// custom validation class | |
$validation->add('name', '名前') | |
->add_rule('trim') | |
->add_rule('required') | |
->add_rule('something_check');// custom validation rule | |
if ($validation->run()) { | |
// valid | |
$validated_inputs = $validation->validated(); | |
} else { | |
// invalid | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* fuel/app/lang/js/validation.php */ | |
return array( | |
'something_check' => ':label が不正です。', | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment