codeigniter4.14
app/Config/Validation.php
次の通り CustomRules::class を追加
----
public $ruleSets = [
Rules::class,
FormatRules::class,
FileRules::class,
CreditCardRules::class,
CustomRules::class
];
app/Config/CustomRules.php
----
<?php
namespace Config;
class CustomRules
{
public function even(string $str, string &$error = null): bool
{
if ((int) $str % 2 !== 0) {
$error = lang('myerrors.evenError');
return false;
}
return true;
}
}
?>
validation rule に even が使えるようになった
$validation->setRules(
'hogehoge' => ['label' => 'hogehoge','rules' => 'even']
);
コメント