このページの2つのバージョン間の差分を表示します。
| 次のリビジョン | 前のリビジョン | ||
|
basic-library:valitron:1.4 [2020/04/18 10:27] y2sunlight 作成 |
basic-library:valitron:1.4 [2020/07/13 09:51] (現在) y2sunlight [バリデーター - Valitron] |
||
|---|---|---|---|
| 行 1: | 行 1: | ||
| - | > TODO: | ||
| - | |||
| - | ----- | ||
| - | |||
| ====== バリデーター - Valitron ====== | ====== バリデーター - Valitron ====== | ||
| Version 1.4 ([[https:// | Version 1.4 ([[https:// | ||
| 行 16: | 行 12: | ||
| * [[basic-library: | * [[basic-library: | ||
| * [[basic-library: | * [[basic-library: | ||
| - | * リクエストルーター - FastRoute | + | * [[basic-library: |
| + | * [[basic-library: | ||
| + | * バリデーター - Valitron | ||
| * [[basic-library: | * [[basic-library: | ||
| * [[basic-library: | * [[basic-library: | ||
| 行 32: | 行 30: | ||
| ===== Valitron について ===== | ===== Valitron について ===== | ||
| - | > TODO: | + | Webアプリケーションの世界では [[https:// |
| + | |||
| + | 但し、バリデーターが機能を重視する余りに他のパッケージと依存関係の為に付随する大量の追加ファイルを取り込むことは避けたいと思います(これは本編のApricotの思想に反します)。そこで、いろいろ探したところ、Apricotの思いにピッタリのものを見つけました。それが '' | ||
| ===== インストール ===== | ===== インストール ===== | ||
| 行 41: | 行 42: | ||
| < | < | ||
| - | TODO: | + | Using version ^1.4 for vlucas/ |
| + | ./ | ||
| + | Loading composer repositories with package information | ||
| + | Updating dependencies (including require-dev) | ||
| + | Package operations: 1 install, 0 updates, 0 removals | ||
| + | - Installing vlucas/ | ||
| + | Writing lock file | ||
| + | Generating autoload files | ||
| + | 1 package you are using is looking for funding. | ||
| + | Use the `composer fund` command to find out more! | ||
| </ | </ | ||
| 行 61: | 行 71: | ||
| ===== テストプログラム ===== | ===== テストプログラム ===== | ||
| - | > TODO: | + | パッケージのテストフォルダ(test\)に、テスト用のコード(valitron.php)を作成します。この例はgithubに記載されているものと同等です。フォームからPostされてくる'' |
| + | |||
| + | <code php valitron.php> | ||
| + | <?php | ||
| + | require __DIR__.'/ | ||
| + | |||
| + | $v = new Valitron\Validator(array(' | ||
| + | $v-> | ||
| + | if($v-> | ||
| + | { | ||
| + | echo "Yay! We're all good!"; | ||
| + | } | ||
| + | else | ||
| + | { | ||
| + | // Errors | ||
| + | print_r($v-> | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | === 実行結果(成功の場合) === | ||
| + | < | ||
| + | Yay! We're all good! | ||
| + | </ | ||
| + | |||
| + | === 実行結果(失敗の場合) === | ||
| + | < | ||
| + | Array ( [name] => Array ( [0] => Name is required ) ) | ||
| + | </ | ||
| + | |||
| + | エラーの場合のメッセージは言語毎に設定できるように配慮されており、バリデーションルールの追加も簡単に出来るようになっています。仔細はの[[https:// | ||
| + | |||
| + | <code php> | ||
| + | $v = new Valitron\Validator($_POST); | ||
| + | </ | ||
| + | |||
| + | \\ | ||