{"id":6598,"date":"2011-12-04T04:37:43","date_gmt":"2011-12-03T19:37:43","guid":{"rendered":"http:\/\/fukata.org\/?p=6598"},"modified":"2017-08-11T22:58:48","modified_gmt":"2017-08-11T22:58:48","slug":"fuelphp-usage-validation","status":"publish","type":"post","link":"https:\/\/blog.fukata.org\/archives\/6598\/","title":{"rendered":"[FuelPHP]Validation\u306e\u4f7f\u3044\u65b9"},"content":{"rendered":"
\u76ee\u6b21<\/p>
\u5148\u65e5\u3001@kenji_s<\/a>\u3055\u3093\u304b\u3089FuelPHP\u306eAdvent Calendar\u304c\u3042\u308b\u304b\u3089\u826f\u304b\u3063\u305f\u3089\u3069\u3046\u305e\u3068\u3044\u3046\u3053\u3068\u3060\u3063\u305f\u306e\u3067\u3001\u53c2\u52a0\u3057\u3066\u307f\u308b\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002Advent Calendar\u521d\u53c2\u52a0\uff01<\/p>\n \u3068\u306f\u8a00\u3046\u3082\u306e\u306eCodeIgniter\u306f\u4ed5\u4e8b\u3067\u3082\u4f7f\u3063\u3066\u3044\u305f\u306e\u3067\u3059\u304c\u3001FuelPHP<\/a>\u306f\u4e00\u5207\u89e6\u3063\u305f\u3053\u3068\u304c\u306a\u3044\u3068\u3044\u3046\u304f\u3089\u3044\u521d\u3081\u3066\u306e\u3082\u306e\u3067\u3001\u305d\u3093\u306a\u81ea\u5206\u306b\u3067\u3082\u4f55\u304b\u66f8\u3051\u308b\u5185\u5bb9\u304c\u306a\u3044\u304b\u3068\u63a2\u3057\u3066\u3001\u307b\u3068\u3093\u3069\u306e\u30b7\u30b9\u30c6\u30e0\u3067\u5fc5\u8981\u306b\u306a\u308b\u3067\u3042\u308d\u3046Validation\u90e8\u5206\u306b\u3064\u3044\u3066\u8abf\u3079\u306a\u304c\u3089\u66f8\u304f\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002\u305d\u306e\u305f\u3081\u3001\u3044\u304f\u3064\u304b\u9593\u9055\u3063\u3066\u3044\u308b\u70b9\u306a\u3069\u304c\u3042\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u304c\u3001\u3082\u3057\u305d\u3046\u3044\u3046\u70b9\u304c\u3042\u308a\u307e\u3057\u305f\u3089\u3001\u30b3\u30e1\u30f3\u30c8\u306a\u308a\u4f55\u306a\u308a\u9802\u3051\u308b\u3068\u52a9\u304b\u308a\u307e\u3059\u3002<\/p>\n <\/p>\n \u3067\u306f\u3001\u65e9\u901f\u57fa\u672c\u7684\u306aValidation\u306e\u4f7f\u3044\u65b9\u3092\u898b\u3066\u3044\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n \u3044\u304d\u306a\u308a\u3067\u3059\u304c\u3001Validation\u306e\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b\u3064\u3044\u3066\u306f\u3001\u3053\u3061\u3089<\/a>\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n \u4eca\u56de\u306f\u3001\u300c\u30e6\u30fc\u30b6\u540d\u300d\u3001\u300c\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u300d\u3068\u3044\u30462\u3064\u306e\u5165\u529b\u9805\u76ee\u306b\u5bfe\u3057\u3066\u306e\u5165\u529b\u5024\u306e\u691c\u8a3c\u51e6\u7406\u3092\u66f8\u3044\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n \u691c\u8a3c\u30c6\u30b9\u30c8\u7528\u306eController_Validation\u3068\u3044\u3046\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u3092\u4f5c\u6210\u3057\u3001\u5165\u529b\u5024\u3092\u691c\u8a3c\u3059\u308b\u30e1\u30bd\u30c3\u30c9\u3068\u3057\u3066\u3001action_validate\u306e\u51e6\u7406\u3092\u4e0b\u8a18\u306e\u3088\u3046\u306b\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n \u307e\u305a\u3001\u300c1. Validation\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u751f\u6210\u300d\u306e\u7b87\u6240\u3067\u3059\u304c\u3001Validation#forge\u30e1\u30bd\u30c3\u30c9\u306f\u3001\u30d5\u30a3\u30fc\u30eb\u30c9\u30bb\u30c3\u30c8\u3068\u547c\u3070\u308c\u308b\u3001\u5165\u529b\u30bd\u30fc\u30b9\u306e\u30b0\u30eb\u30fc\u30d7\u3060\u3068\u500b\u4eba\u7684\u306b\u306f\u6349\u3048\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u3001\u305d\u306e\u30b0\u30eb\u30fc\u30d7\u306e\u540d\u524d\u3092\u5f15\u6570\u306b\u6e21\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u30b0\u30eb\u30fc\u30d7\u304c1\u3064\u3057\u304b\u306a\u3044\u5834\u5408\u306f\u672a\u6307\u5b9a\uff08\u30c7\u30d5\u30a9\u30eb\u30c8\uff1adefault\uff09\u3001\u30b0\u30eb\u30fc\u30d7\u304c2\u3064\u4ee5\u4e0a\u306a\u308b\u3088\u3046\u306a\u8907\u96d1\u306a\u5834\u5408\u306b\u306f\u3001\u540d\u524d\u3092\u6307\u5b9a\u3057\u3066\u3001\u8907\u6570\u306eValidation\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u751f\u6210\u3001\u7ba1\u7406\u3059\u308b\u3053\u3068\u3082\u51fa\u6765\u307e\u3059\u3002<\/p>\n \u4f8b\u3048\u3070\u3001\u30d0\u30c3\u30c1\u7b49\u30671\u30ea\u30af\u30a8\u30b9\u30c8\u4e2d\u306b\u8907\u6570\u306e\u5916\u90e8\u30ea\u30bd\u30fc\u30b9\u3092\u53d6\u308a\u8fbc\u3080\u5834\u5408\u306b\u3001\u305d\u308c\u3089\u306e\u5024\u306e\u691c\u8a3c\u3092\u884c\u3046\u5834\u5408\u306b\u8907\u6570\u306eValidation\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u4f7f\u3048\u308b\u3068\u4fbf\u5229\u3067\u3059\u3002<\/p>\n \u6b21\u306b\u30012.1, 2.2\u3067\u691c\u8a3c\u30eb\u30fc\u30eb\u3092\u8a2d\u5b9a\u3057\u3066\u3044\u307e\u3059\u304c\u3001add_rule\u306e\u3088\u3046\u306b\u30c1\u30a7\u30a4\u30f3\u30e1\u30bd\u30c3\u30c9\u5f62\u5f0f\u3067\u6307\u5b9a\u3059\u308b\u65b9\u6cd5\u3068\u3001CodeIgniter\u306e\u3088\u3046\u306b\u4e00\u5ea6\u306b\u5168\u3066\u8a2d\u5b9a\u3059\u308b\u65b9\u6cd5\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n \u307e\u305f\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u63d0\u4f9b\u3055\u308c\u3066\u3044\u308b\u691c\u8a3c\u30eb\u30fc\u30eb\u306f\u3053\u3061\u3089<\/a>\u306b\u8a18\u8f09\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n \u3067\u3001\u6700\u5f8c\u306e\u300c3. \u691c\u8a3c\u5b9f\u884c\u300d\u306e\u90e8\u5206\u3067\u691c\u8a3c\u30eb\u30fc\u30eb\u306b\u57fa\u3065\u3044\u3066\u691c\u8a3c\u3092\u5b9f\u884c\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n \u306e\u3088\u3046\u306b\u3001Fuel\\Core\\Validation#show_errors\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3046\u3053\u3068\u3067\u3001\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u7528\u306eHTML\u6587\u5b57\u5217\u3092\u8fd4\u3057\u3066\u304f\u308c\u307e\u3059\u3002<\/p>\n \u305f\u3060\u3057\u3001FuelPHP\u3067\u306f\u6a19\u6e96\u3067View\u5185\u3067\u4f7f\u7528\u3055\u308c\u308b\u6587\u5b57\u5217\u3084__toString\u30e1\u30bd\u30c3\u30c9\u304c\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u95a2\u3057\u3066\u306f\u30a8\u30b9\u30b1\u30fc\u30d7\u3055\u308c\u308b\u306e\u3067\u3001\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u5074\u3067show_errors\u306e\u7d50\u679c\u3092View\u306b\u6e21\u3057\u3066\u3082\u30bf\u30b0\u304c\u30a8\u30b9\u30b1\u30fc\u30d7\u3055\u308c\u305f\u72b6\u614b\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002\u305d\u306e\u305f\u3081\u3001View\u5074\u3067\u5143\u306e\u72b6\u614b\u306b\u623b\u3059\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n \u3053\u306e\u3001View\u5185\u3067\u4f7f\u7528\u3055\u308c\u308b\u5909\u6570\u306e\u30a8\u30b9\u30b1\u30fc\u30d7\u51e6\u7406\u306b\u3064\u3044\u3066\u306f\u3001config.php\u306b\u3042\u308bsecurity\u30bb\u30af\u30b7\u30e7\u30f3\u306eoutput_filter, auto_filter_ouput, whitelisted_classes\u306e\u8a2d\u5b9a\u5024\u3092\u53c2\u7167\u3057\u3066\u304a\u308a\u3001\u5404\u5024\u306b\u3064\u3044\u3066\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u610f\u5473\u5408\u3044\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n \u8a73\u3057\u304f\u306f\u3001\u516c\u5f0f\u306eSecurity\u30af\u30e9\u30b9\u306e\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n Security – Classes – FuelPHP Documentation<\/a><\/p>\n \u30a8\u30b9\u30b1\u30fc\u30d7\u305b\u305a\u306b\u30d3\u30e5\u30fc\u306b\u30c7\u30fc\u30bf\u3092\u6e21\u3057\u305f\u3044\u5834\u5408\u306b\u306f\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306bView\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306b\u5909\u6570\u3092\u76f4\u63a5\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u3067\u53ef\u80fd\u3067\u3059\u3002<\/p>\n \u5834\u5408\u306b\u3088\u3063\u3066\u306f\u8a2d\u5b9a\u3057\u305f\u9805\u76ee\u5168\u3066\u3067\u306f\u306a\u304f\u3001\u4e00\u90e8\u306e\u9805\u76ee\u306b\u3064\u3044\u3066\u306e\u307f\u691c\u8a3c\u3057\u305f\u3044\u3068\u3044\u3046\u3053\u3068\u304c\u3042\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002\u305d\u3046\u3044\u3063\u305f\u4f7f\u3044\u65b9\u3092\u3057\u305f\u3044\u5834\u5408\u306b\u306f\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306b\u3059\u308b\u3053\u3068\u3067\u90e8\u5206\u7684\u306a\u691c\u8a3c\u304c\u884c\u3048\u307e\u3059\u3002<\/p>\n \u305f\u3060\u3057\u3001\u3053\u306e\u5834\u5408\u306f\u3001\u9001\u4fe1\u3055\u308c\u305f\u60c5\u5831\u306e\u4e2d\u306bemail\u304c\u542b\u307e\u308c\u3066\u3044\u306a\u3044\u5834\u5408\u306e\u307f\u3067\u3059\u3002\u30c7\u30fc\u30bf\u304c\u9001\u3089\u308c\u3066\u304d\u3066\u3044\u3066\u3001\u691c\u8a3c\u30eb\u30fc\u30eb\u3082\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u308b\u304c\u3001\u5b9f\u969b\u306b\u691c\u8a3c\u3057\u305f\u3044\u306e\u306f\u4e00\u90e8\u306e\u307f\u3001\u3068\u3044\u3046\u6642\u306b\u306f\u4e0b\u8a18\u306e\u3088\u3046\u306b\u3001\u7b2c\u4e8c\u5f15\u6570\u306b\u90e8\u5206\u691c\u8a3c\u3092\u884c\u3046\u9805\u76ee\u3092\u914d\u5217\u3067\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n \u3053\u308c\u307e\u3067\u306f\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u63d0\u4f9b\u3055\u308c\u3066\u3044\u308b\u691c\u8a3c\u30eb\u30fc\u30eb\u306e\u307f\u3092\u4f7f\u7528\u3057\u3066\u304d\u307e\u3057\u305f\u3002\u305f\u3060\u3001\u696d\u52d9\u3067\u5229\u7528\u3057\u3066\u3044\u308b\u5834\u5408\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u5024\u3068\u7167\u5408\u3057\u305f\u308a\u306a\u3069\u3001\u8db3\u308a\u306a\u3044\u90e8\u5206\u3068\u3044\u3046\u306e\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n \u305d\u3053\u3067\u3001app\/classes\/myvalidation.php<\/strong>\u306b\u4e0b\u8a18\u306e\u3088\u3046\u306a\u72ec\u81ea\u306eValidation\u30af\u30e9\u30b9\u3068Static\u306a\u691c\u8a3c\u7528\u30e1\u30bd\u30c3\u30c9\u3092\u5b9a\u7fa9\u3057\u307e\u3059\u3002\u691c\u8a3c\u7528\u30e1\u30bd\u30c3\u30c9\u306e\u30d7\u30ec\u30d5\u30a3\u30c3\u30af\u30b9\u306f_validation_<\/strong>\u3067\u3042\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n \u30d5\u30a1\u30a4\u30eb\u540d\u306b\u3064\u3044\u3066\u306f\u3001\u4e0b\u8a18\u306eadd_callable\u3067\u6307\u5b9a\u3057\u3066\u3044\u308b\u5024\u3068\u4e00\u81f4\u3057\u3066\u3044\u308c\u3070\u826f\u3044\u3067\u3059\u3002<\/p>\n \u3053\u308c\u3092\u5148\u7a0b\u306e\u691c\u8a3c\u30eb\u30fc\u30eb\u3067\u5229\u7528\u3059\u308b\u306b\u306f\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306b\u5909\u66f4\u3057\u307e\u3059\u3002\u30ab\u30b9\u30bf\u30e0\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u7528\u306e\u30e1\u30c3\u30bb\u30fc\u30b8\u306b\u3064\u3044\u3066\u3082\u4e0b\u306e\u65b9\u306b\u66f8\u3044\u3066\u3044\u308b\u300c\u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u5909\u66f4\u300d\u3067\u66f8\u3044\u3066\u3044\u308bvalidation.php\u306b\u8ffd\u8a18\u3059\u308c\u3070\u5927\u4e08\u592b\u3067\u3059\u3002<\/p>\n \u4eca\u56de\u306e\u30b5\u30f3\u30d7\u30eb\u3067\u306f\u3001DB\u3068\u3084\u308a\u53d6\u308a\u3059\u308b\u90e8\u5206\u306b\u3064\u3044\u3066\u306f\u66f8\u3044\u3066\u3044\u307e\u305b\u3093\u304c\u3001\u5b9f\u969b\u306b\u306f\u3001_validation_myvalidmodel\u306e\u4e2d\u3067\u3001DB\u306b\u554f\u3044\u5408\u308f\u305b\u306a\u3069\u3092\u884c\u3063\u305f\u308a\u3059\u308b\u30b3\u30fc\u30c9\u3092\u66f8\u304d\u307e\u3059\u3002\u307e\u305f\u3001\u5148\u307b\u3069\u5b9a\u7fa9\u3057\u305f\u3001_validation_myvalid\u306b\u306f\u7121\u304b\u3063\u305f$option\u3068\u3044\u3046\u5f15\u6570\u304c\u8ffd\u52a0\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u3053\u308c\u306f\u3001min_length\u3084max_length\u306e\u3088\u3046\u306b\u5f15\u6570\u3092\u53d7\u3051\u53d6\u308b\u5909\u6570\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002$option\u5f15\u6570\u306b\u95a2\u3057\u3066\u306f\u3001\u5148\u307b\u3069\u5b9a\u7fa9\u3057\u305f_validation_myvalid\u30e1\u30bd\u30c3\u30c9\u3067\u3082\u540c\u3058\u69d8\u306b\u7b2c\u4e8c\u5f15\u6570\u306b\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u53d7\u3051\u53d6\u308c\u307e\u3059\u3002<\/p>\n \u4eca\u56de\u306e\u5834\u5408\u3001\u5165\u529b\u3055\u308c\u305f\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u304c$option\u306b\u6307\u5b9a\u3055\u308c\u305f\u5024\u3068\u4e00\u81f4\u3057\u3066\u3044\u308b\u304b\u3068\u3044\u3046\u306e\u3092\u30c1\u30a7\u30c3\u30af\u3057\u3066\u3044\u307e\u3059\u3002\u3055\u3089\u306b\u3001Validation::active()\u3092\u4f7f\u3044\u3001\u305d\u306e\u6642\u691c\u8a3c\u4e2d\u306eFieldset\u3092\u53d6\u5f97\u3057\u3001\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u3082\u8a2d\u5b9a\u3059\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n \u30d5\u30a1\u30a4\u30eb\uff1aapp\/classes\/model\/validation.php<\/strong><\/p>\n \u3053\u308c\u3092\u5148\u7a0b\u306e\u691c\u8a3c\u30eb\u30fc\u30eb\u3067\u5229\u7528\u3059\u308b\u306b\u306f\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306b\u5909\u66f4\u3057\u307e\u3059\u3002<\/p>\n \u4e0a\u8a18\u306eValidation\u306e\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b\u3082\u66f8\u304b\u308c\u3066\u3044\u307e\u3059\u304c\u3001fuel\/app\/config\/config.php\u306b\u4e0b\u8a18\u306e\u3088\u3046\u306a\u30bb\u30af\u30b7\u30e7\u30f3\u3092\u8ffd\u52a0\u3059\u308b\u3053\u3068\u3067\u3001Fuel\\Core\\Validation#show_errors\u30e1\u30bd\u30c3\u30c9\u6642\u306eHTML\u3092\u5909\u66f4\u3059\u308b\u4e8b\u304c\u51fa\u6765\u307e\u3059\u3002<\/p>\n CodeIgniter\u306eForm_Validation\u306fPOST\u306e\u307f\u5bfe\u5fdc\u3057\u3066\u3044\u307e\u3057\u305f\u304c\u3001FuelPHP\u306eValidation\u306fGET, POST, PUT, DELETE\u306e\u5404\u30e1\u30bd\u30c3\u30c9\u306b\u5bfe\u5fdc\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n fuel\/core\/lang\/en\/validation.php\u3092\u53c2\u8003\u306b\u3001fuel\/app\/lang\/en\/validation.php\u306b\u305d\u308c\u305e\u308c\u306e\u30eb\u30fc\u30eb\u306b\u5bfe\u3057\u3066\u306e\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u8a18\u8f09\u3059\u308c\u3070\u5909\u66f4\u3067\u304d\u307e\u3059\u3002\u307e\u305f\u3001en\u3067\u306f\u306a\u304f\u3001fuel\/app\/lang\/ja\/validation.php\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u3067\u3001\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u56fd\u969b\u5316\u306b\u3082\u5bfe\u5fdc\u3059\u308b\u4e8b\u304c\u51fa\u6765\u307e\u3059\u3002\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u65e5\u672c\u8a9e\u306b\u3057\u305f\u3044\u5834\u5408\u306f\u3001config.php\u306b\u3042\u308blanguage\u306e\u9805\u76ee\u3092en\u304b\u3089ja\u306b\u5909\u66f4\u3059\u308b\u3060\u3051\u3067\u5927\u4e08\u592b\u3060\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n \u4eca\u56de\u3001Validation\u5468\u308a\u3092\u4f7f\u7528\u3059\u308b\u306b\u5f53\u305f\u3063\u3066\u3001\u4e3b\u306b\u8abf\u3079\u305f\u30d5\u30a1\u30a4\u30eb\u7fa4\u3067\u3059\u3002<\/p>\n CodeIgniter\u306eForm_Validation\u3068\u4f3c\u3066\u3044\u308b\u7b87\u6240\u304c\u3044\u304f\u3064\u304b\u3042\u308b\u305f\u3081\u3001CodeIgniter\u3092\u4ee5\u524d\u4f7f\u7528\u3057\u3066\u3044\u305f\u4eba\u306b\u53d6\u3063\u3066\u306f\u305d\u308c\u307b\u3069\u9055\u548c\u611f\u306a\u304f\u4f7f\u3048\u308b\u3093\u3058\u3083\u306a\u3044\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n \u521d\u306eAdvent Calendar\u53c2\u52a0\u304b\u3064\u3001\u4eca\u56de\u521d\u3081\u3066\u307e\u3068\u3082\u306b\u8abf\u3079\u305fFW\u3060\u3063\u305f\u306e\u3067\u3084\u3051\u306b\u6642\u9593\u304c\u304b\u304b\u3063\u3066\u3057\u307e\u3044\u307e\u3057\u305f\u3002\u307e\u305f\u3001\u629c\u3051\u306a\u3069\u304c\u3042\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002\u3082\u3057\u3001\u9593\u9055\u3044\u7b49\u304c\u3042\u308a\u307e\u3057\u305f\u3089\u6307\u6458\u3057\u3066\u3044\u305f\u3060\u3051\u308c\u3070\u4fee\u6b63\u3057\u307e\u3059\u3002\u3068\u308a\u3042\u3048\u305a\u3001\u66f8\u304d\u7d42\u3048\u308c\u3066\u826f\u304b\u3063\u305f\u3067\u3059\u3002<\/p>\n \u6700\u5f8c\u306b\u3001Advent Calendar<\/a>\u3067\u3059\u304c\u3001\u307e\u3060\u307e\u3060\u53c2\u52a0\u8005\u304c\u5c11\u306a\u3044\u306e\u3067\u3001\u826f\u304b\u3063\u305f\u3089\u662f\u975e\u53c2\u52a0\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n 3\u65e5\u76ee\uff1a@NEKOGET<\/a>\u3055\u3093 \u306d\u3053\u3052\u3063\u3068\u3077\u308c\u3059 \u00bb Model-View-Controller\u305d\u3057\u3066ViewModel [FuelPHP]<\/a> FuelPHP Advent Calendar 2011 : ATND \u5148\u65e5\u3001@kenji_s\u3055\u3093\u304b\u3089FuelPHP\u306eAdvent Calendar\u304c\u3042\u308b\u304b\u3089\u826f\u304b\u3063\u305f\u3089\u3069\u3046\u305e\u3068\u3044\u3046\u3053\u3068\u3060\u3063\u305f\u306e\u3067\u3001\u53c2\u52a0 … \u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":2,"featured_media":9223372036854775807,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1980],"tags":[947,946],"_links":{"self":[{"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/posts\/6598"}],"collection":[{"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/comments?post=6598"}],"version-history":[{"count":0,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/posts\/6598\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/media\/9223372036854775807"}],"wp:attachment":[{"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/media?parent=6598"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/categories?post=6598"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/tags?post=6598"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}\u57fa\u672c\u7684\u306a\u691c\u8a3c<\/span><\/h2>\n
\u691c\u8a3c\u90e8\u5206<\/span><\/h3>\n
\r\n\/\/ 1. Validation\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u751f\u6210\r\n$validation = Validation::forge();\r\n\r\n\/\/ 2. \u691c\u8a3c\u30eb\u30fc\u30eb\u8a2d\u5b9a\r\n\/\/ 2.1. username\u9805\u76ee\u306e\u691c\u8a3c\u30eb\u30fc\u30eb\u8a2d\u5b9a\r\n$validation->add('username', '\u30e6\u30fc\u30b6\u540d')\r\n ->add_rule('required')\r\n ->add_rule('mix_length', 4)\r\n ->add_rule('max_length', 10);\r\n\r\n\/\/ 2.2. email\u9805\u76ee\u306e\u691c\u8a3c\u30eb\u30fc\u30eb\u8a2d\u5b9a\r\n$validation->add_field('email', '\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9', 'required|min_length[10]|max_length[128]');\r\n\r\n\/\/ 3. \u691c\u8a3c\u5b9f\u884c\r\nif ($validation->run()) {\r\n \/\/ 3.1. \u691c\u8a3c\u6210\u529f\r\n return Response::forge(View::forge('validation\/index'));\r\n} else {\r\n \/\/ 3.2. \u691c\u8a3c\u5931\u6557\r\n return Response::forge(View::forge('validation\/index'));\r\n}\r\n<\/pre>\n
\u30a8\u30e9\u30fc\u8868\u793a<\/span><\/h3>\n
\r\n$errors = $validation->error(); \/\/ \u30a8\u30e9\u30fc\u306e\u9805\u76ee\u3068\u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u9023\u60f3\u914d\u5217\u3092\u53d6\u5f97\r\n$error_html = $validation->show_errors(); \/\/ \u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u7528HTML\u3092\u53d6\u5f97\r\n$error_input = $validation->input(); \/\/ \u691c\u8a3c\u306b\u4f7f\u7528\u3057\u305f\u5165\u529b\u5024\u3092\u9805\u76ee\u3068\u5024\u306e\u9023\u60f3\u914d\u5217\u3067\u53d6\u5f97\r\n<\/pre>\n
\n
\r\n$view = View::forge('validation\/index');\r\n$view->set_safe('error_html', $validation->show_errors());\r\n<\/pre>\n
\u90e8\u5206\u691c\u8a3c<\/span><\/h3>\n
\r\n\/\/ \u7b2c1\u5f15\u6570\u306f\u3001\u691c\u8a3c\u5bfe\u8c61\u306e\u9805\u76ee\u540d\u3068\u5024\u306e\u9023\u60f3\u914d\u5217\r\n\/\/ \u7b2c2\u5f15\u6570\u306f\u3001\u90e8\u5206\u691c\u8a3c\u3092\u884c\u3046\u304b\u3069\u3046\u304b\r\nif ($validation->run(array('username' => Input::post('username')), true)) {\r\n \/\/ \u691c\u8a3c\u6210\u529f\r\n} else {\r\n \/\/ \u691c\u8a3c\u5931\u6557\r\n}\r\n<\/pre>\n
\r\n\/\/ \u7b2c1\u5f15\u6570\u306f\u3001\u691c\u8a3c\u5bfe\u8c61\u306e\u9805\u76ee\u540d\u3068\u5024\u306e\u9023\u60f3\u914d\u5217\r\n\/\/ \u7b2c2\u5f15\u6570\u306f\u3001\u90e8\u5206\u691c\u8a3c\u3092\u884c\u3046\u9805\u76ee\r\nif ($validation->run(array('username' => Input::post('username')), array('username'))) {\r\n \/\/ \u691c\u8a3c\u6210\u529f\r\n} else {\r\n \/\/ \u691c\u8a3c\u5931\u6557\r\n}\r\n<\/pre>\n
\u30ab\u30b9\u30bf\u30e0\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3<\/span><\/h2>\n
\r\nclass Myvalidation {\r\n public static function _validation_myvalid($val) {\r\n return $val == 'fukata';\r\n }\r\n}\r\n<\/pre>\n
\r\n\/\/ 2. \u691c\u8a3c\u30eb\u30fc\u30eb\u8a2d\u5b9a\r\n$validation->add_callable('myvalidation');\r\n\/\/ 2.1. username\u9805\u76ee\u306e\u691c\u8a3c\u30eb\u30fc\u30eb\u8a2d\u5b9a\r\n$validation->add('username', '\u30e6\u30fc\u30b6\u540d')\r\n ->add_rule('required')\r\n ->add_rule('mix_length', 4)\r\n ->add_rule('max_length', 10)\r\n ->add_rule('myvalid');\r\n<\/pre>\n
\u30e2\u30c7\u30eb\u3068\u306e\u9023\u643a<\/span><\/h3>\n
\r\nclass Model_Validation extends Model {\r\n public static function _validation_myvalidmodel($val, $option) {\r\n if ($option != $val) {\r\n \/\/ \u72ec\u81ea\u3067\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u8a2d\u5b9a\r\n Validation::active()->set_message('myvalidmodel', ':label is hogehoge');\r\n return false;\r\n } else {\r\n return true;\r\n } \r\n } \r\n}\r\n<\/pre>\n
\r\n\/\/ 2.2. email\u9805\u76ee\u306e\u691c\u8a3c\u30eb\u30fc\u30eb\u8a2d\u5b9a\r\n$validation->add_model('Model_Validation');\r\n$validation->add_field('email', '\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9', 'required|min_length[10]|max_length[128]|myvalidmodel[fukata@example.com]');\r\n<\/pre>\n
\u30a8\u30e9\u30fc\u7528\u30bf\u30b0\u306e\u30ab\u30b9\u30bf\u30de\u30a4\u30ba<\/span><\/h2>\n
\r\n\/** \r\n * Validation settings\r\n *\/\r\n'validation' => array(\r\n 'open_list' => '
',\r\n 'close_list' => '<\/ul>',\r\n 'open_error' => '
\u691c\u8a3c\u53ef\u80fd\u306aHTTP\u30e1\u30bd\u30c3\u30c9<\/span><\/h2>\n
\u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u5909\u66f4<\/span><\/h2>\n
\u95a2\u9023\u30d5\u30a1\u30a4\u30eb<\/span><\/h2>\n
\n
\u307e\u3068\u3081<\/span><\/h2>\n
\n5\u65e5\u76ee\uff1a@madmamor<\/a>\u3055\u3093 FuelPHP\u3067Facebook\u30a2\u30d7\u30ea\u3092\u4f5c\u3063\u3066\u307f\u3088\u3046\u3002\u6e96\u5099\u7de8\u3002<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"