{"id":310,"date":"2018-12-21T23:52:37","date_gmt":"2018-12-21T14:52:37","guid":{"rendered":"https:\/\/manadream.net\/kat_blog\/?p=310"},"modified":"2019-10-09T17:34:09","modified_gmt":"2019-10-09T08:34:09","slug":"zend-validate-any-required","status":"publish","type":"post","link":"https:\/\/katblog.manadream.net\/index.php\/2018\/12\/21\/zend-validate-any-required\/","title":{"rendered":"\u3010Zend\u3011zend validate\u3067\u3001\u3044\u305a\u308c\u304b1\u3064\u3092\u5fc5\u9808\u306b\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<div class=\"wp-block-image\">\n<figure class=\"aligncenter is-resized\"><\/figure>\n<\/div>\n<p>\u3069\u3046\u3082\u3001kat\u3067\u3059\u3002<\/p>\n<p>\u7a81\u7136\u3067\u3059\u304c\u3001zend validate\u3067\u3001\u3053\u3093\u306a\u3053\u3068\u601d\u3063\u305f\u308a\u3057\u307e\u305b\u3093\u304b\uff1f<\/p>\n<div class=\"simple-box4\">\u30fb\u8907\u6570\u306e\u5165\u529b\u9805\u76ee\u306e\u3046\u3061\u3001\u3069\u308c\u304b\u4e00\u3064\u3060\u3051\u3092\u5fc5\u9808\u306b\u3057\u305f\u3044<br>\u3000<span style=\"font-size: 12pt;\">\u203b\u9006\u306b\u8a00\u3046\u3068\u3001\u8907\u6570\u9805\u76ee\u306e\u5168\u3066\u304c\u7a7a\u3060\u3063\u305f\u3068\u304d\u3060\u3051\u30a8\u30e9\u30fc\u306b\u3057\u305f\u3044\u3002<\/span><\/div>\n<p>\u305d\u3093\u306a\u3068\u304d\u3001\u30b0\u30b0\u3063\u3066\u3082\u4e2d\u3005\u7b54\u3048\u304c\u898b\u3064\u304b\u3089\u306a\u3044\uff5e\uff01<\/p>\n<p>\u3066\u3053\u3068\u3042\u308a\u307e\u3059\u3088\u306d\u3002<\/p>\n<p>\u4eca\u56de\u306f\u3001\u4e0a\u8a18\u306e\u554f\u984c\u3092<strong>\u7c21\u5358\u306b\u89e3\u6c7a\u3059\u308b\u65b9\u6cd5<\/strong>\u306b\u3064\u3044\u3066\u66f8\u3044\u3066\u3044\u3053\u3046\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n<h2 class=\"wp-block-heading\">\u6e96\u5099<\/h2>\n\n\n<p>\u3053\u3053\u3067\u306f\u3001\u30e6\u30fc\u30b6\u30fc\u306e\u691c\u7d22\u753b\u9762\u3092\u4f8b\u306b\u3057\u3066\u9032\u3081\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001\u691c\u7d22\u9805\u76ee\u306b\u3001\u300c\u540d\u524d\u300d\u300c\u751f\u5e74\u6708\u65e5\uff08From\uff09\u300d\u300c\u751f\u5e74\u6708\u65e5\uff08To\uff09\u300d\u3068\u3044\u3046\u9805\u76ee\u304c\u3042\u308b\u3068\u3057\u307e\u3059\u3002<\/p>\n<p>\u30fbexample.html<\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: xml; title: ; notranslate\" title=\"\">\n\u30e6\u30fc\u30b6\u30fc\u540d\uff1a&lt;input name=&quot;user_name&quot; type=&quot;text&quot; value=&quot;&quot;&gt;\n\u751f\u5e74\u6708\u65e5(From)\uff1a&lt;input name=&quot;birth_day_from&quot; type=&quot;text&quot; value=&quot;&quot;&gt;\n\u751f\u5e74\u6708\u65e5(To)\uff1a&lt;input name=&quot;birth_day_to&quot; type=&quot;text&quot; value=&quot;&quot;&gt;\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u5b9f\u88c5<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u5fc5\u9808\u306e\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306e\u307f\u306e\u5834\u5408<\/h3>\n\n\n<p>\u305d\u308c\u3067\u306f\u3001\u5b9f\u969b\u306b\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u5b9f\u88c5\u3057\u307e\u3059\u3002<\/p>\n<p>\u307e\u305a\u306f\u3001\u300c\u30e6\u30fc\u30b6\u30fc\u540d\u300d\u306b\u3001<strong>\u300c\u3044\u305a\u308c\u304b\u306e\u9805\u76ee\u304c\u5fc5\u9808\u300d\u4ee5\u5916\u306e\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u304c\u7121\u3044<\/strong>\u5834\u5408\u3067\u8aac\u660e\u3057\u3066\u3044\u304d\u307e\u3059\u3002\uff08\u4ed6\u306e\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u304c\u3042\u308b\u5834\u5408\u306f<a href=\"#i-4\">\u6b21\u9805<\/a>\u3067\u8aac\u660e\u3057\u3066\u3044\u307e\u3059\u3002\uff09<\/p>\n<p>\u65e9\u901f\u3067\u3059\u304c\u3001\u5b9f\u88c5\u5185\u5bb9\u306f\u4e0b\u8a18\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u30fbexample.php<\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n'user_name' =&gt; &#x5B;\n  'continue_if_empty' =&gt; true,\u3000\/\/ \u2190 \u91cd\u8981\uff01\uff01\n  'required' =&gt; true,\n  'validators' =&gt; &#x5B;\n    &#x5B;\n      'name' =&gt; 'callback',\n      'options' =&gt; &#x5B;\n        'messages' =&gt; &#x5B;\n          'callbackValue' =&gt; &quot;\u30e6\u30fc\u30b6\u30fc\u540d\u3001\u751f\u5e74\u6708\u65e5\u306e\u3044\u305a\u308c\u304b\u306f\u5fc5\u9808\u3067\u3059\u3002&quot;,\n        ],\n        'callback' =&gt; function($value, $context = array()) {\n          $userName = $value;\n          $birthDayFrom = $context&#x5B;'birth_day_from'];\n          $birthDayTo = $context&#x5B;'birth_day_to'];\n\n          \/\/ \u5168\u3066\u672a\u5165\u529b\u306e\u5834\u5408\u306e\u307ffalse\u3092\u8fd4\u3059\n          return ($userName || $birthDayFrom || $birthDayTo );\n        },\n      ],\n    ]\n  ],\n],\n'birth_day_from' =&gt; &#x5B;\n  \u30fb\u30fb\u30fb\n],\n'birth_day_to' =&gt; &#x5B;\n  \u30fb\u30fb\u30fb\n],\n<\/pre><\/div>\n\n\n<p>\u3053\u3053\u3067\u91cd\u8981\u3068\u306a\u308b\u306e\u304c\u3001<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n  'continue_if_empty' =&gt; true,\n  'required' =&gt; true,\n<\/pre><\/div>\n\n\n<p>\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u901a\u5e38\u3001&#8217;required&#8217;\u304ctrue\u306e\u5834\u5408\u306b\u7a7a\u306e\u5024\u304c\u6e21\u3063\u3066\u304f\u308b\u3068\u3001<strong>\u4ed6\u306e\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u30c1\u30a7\u30c3\u30af\u3092\u884c\u308f\u305a\u306b\u5fc5\u9808\u30c1\u30a7\u30c3\u30af\u30a8\u30e9\u30fc\u306e\u307f\u767a\u751f<\/strong>\u3055\u305b\u3066\u7d42\u4e86\u3057\u307e\u3059\u304c\u3001&#8217;continue_if_empty&#8217;\u3092true\u306b\u3059\u308b\u3053\u3068\u3067\u3001<strong>\u7a7a\u306e\u5834\u5408\u3067\u3082\u4ed6\u306e\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306e\u30c1\u30a7\u30c3\u30af\u307e\u3067\u884c\u3063\u3066\u304f\u308b<\/strong>\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u5f8c\u306fcallback\u95a2\u6570\u306b\u3001\u884c\u3044\u305f\u3044\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306e\u5185\u5bb9\u3092\u8a18\u8f09\u3059\u308b\u3060\u3051\u3067\u3059\u3002\uff08false\u3092return\u3057\u305f\u5834\u5408\u306b\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3059\u3002\uff09<\/p>\n\n\n\n<p><span style=\"color: #ff0000;\"><strong>\u305f\u3060\u3057\u3001\u3053\u306e\u5834\u5408\u300c\u30e6\u30fc\u30b6\u30fc\u540d\u300d\u306b\u4ed6\u306e\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u8ffd\u52a0\u3059\u308b\u3068\u3001\u7a7a\u306e\u5834\u5408\u3067\u3082\u5168\u3066\u306e\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u304c\u52d5\u3044\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/strong><\/span><\/p>\n\n\n\n<p>\u305d\u306e\u5834\u5408\u306e\u5bfe\u51e6\u6cd5\u306f\u3001\u6b21\u9805\u3067\u8aac\u660e\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u4ed6\u306e\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3068\u7d44\u307f\u5408\u308f\u305b\u305f\u3044\u5834\u5408<\/h3>\n\n\n<p>\u4eca\u5ea6\u306f\u3001\u300c\u30e6\u30fc\u30b6\u30fc\u540d\u300d\u306b\u3001\u300c25\u6587\u5b57\u307e\u3067\u300d\u7b49\u3001\u4ed6\u306e\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u304c\u3042\u308b\u5834\u5408\u3067\u8aac\u660e\u3057\u307e\u3059\u3002<\/p>\n<p>\u4ed6\u306e\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u304c\u306a\u3044\u5834\u5408\u3060\u3068\u524d\u9805\u3067\u554f\u984c\u3042\u308a\u307e\u305b\u3093\u304c\u3001\u4ed6\u306e\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u304c\u3042\u308b\u5834\u5408\u306f\u3053\u3061\u3089\u306e\u66f8\u304d\u65b9\u306b\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u307e\u305a\u3001\u9069\u5f53\u306ahidden\u306einput\u30bf\u30b0\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<p>\u30fbexample.html<\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: xml; title: ; notranslate\" title=\"\">\n\u30e6\u30fc\u30b6\u30fc\u540d\uff1a&lt;input name=&quot;user_name&quot; type=&quot;text&quot; value=&quot;&quot;&gt;\n\u751f\u5e74\u6708\u65e5(From)\uff1a&lt;input name=&quot;birth_day_from&quot; type=&quot;text&quot; value=&quot;&quot;&gt;\n\u751f\u5e74\u6708\u65e5(To)\uff1a&lt;input name=&quot;birth_day_to&quot; type=&quot;text&quot; value=&quot;&quot;&gt;\n&lt;!-- \u4e0b\u8a18\u306e\u884c\u3092\u8ffd\u52a0 --&gt;\n&lt;input name=&quot;required_field&quot; type=&quot;hidden&quot; value=&quot;&quot;&gt;\n<\/pre><\/div>\n\n\n<p>\u6b21\u306b\u3001\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u4fee\u6b63\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u30fbexample.php<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n'user_name' =&gt; &#x5B; \/\/ \u3053\u308c\u306f\u30e6\u30fc\u30b6\u30fc\u540d\u306e\u5225\u306e\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3067\u3059\u3002\n  'validators' =&gt; &#x5B;\n    &#x5B;\n      'name' =&gt; 'stringLength',\n      'options' =&gt; &#x5B;\n        'max' =&gt; 25,\n        'messages' =&gt; &#x5B;\n          'stringLengthTooLong' =&gt; '\u30e6\u30fc\u30b6\u30fc\u540d\u306f25\u6587\u5b57\u4ee5\u4e0b\u3067\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044'\n        ]\n      ]\n    ]\n  ]\n],\n'birth_day_from' =&gt; &#x5B;\n  \u30fb\u30fb\u30fb\n],\n'birth_day_to' =&gt; &#x5B;\n  \u30fb\u30fb\u30fb\n],\n'required_field' =&gt; &#x5B; \/\/ \u3053\u308c\u304c\u300c\u3044\u305a\u308c\u304b\u5fc5\u9808\u300d\u306e\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3067\u3059\u3002\n  'continue_if_empty' =&gt; true,\n  'required' =&gt; true,\n  'validators' =&gt; &#x5B;\n    &#x5B;\n      'name' =&gt; 'callback',\n      'options' =&gt; &#x5B;\n        'messages' =&gt; &#x5B;\n          'callbackValue' =&gt; &quot;\u30e6\u30fc\u30b6\u30fc\u540d\u3001\u751f\u5e74\u6708\u65e5\u306e\u3044\u305a\u308c\u304b\u306f\u5fc5\u9808\u3067\u3059\u3002&quot;,\n        ],\n        'callback' =&gt; function($value, $context = array()) {\n          $userName = $context&#x5B;'user_name'];\n          $birthDayFrom = $context&#x5B;'birth_day_from'];\n          $birthDayTo = $context&#x5B;'birth_day_to'];\n\n          \/\/ \u5168\u3066\u672a\u5165\u529b\u306e\u5834\u5408\u306e\u307ffalse\u3092\u8fd4\u3059\n          return ($userName || $birthDayFrom || $birthDayTo );\n        },\n      ],\n    ]\n  ],\n],\n<\/pre><\/div>\n\n\n<p>\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u5909\u308f\u3063\u305f\u306e\u306f\u3001&#8217;user_name&#8217;\u3067\u306f\u306a\u304f\u3001<strong>&#8216;required_field&#8217;\u306e\u914d\u5217\u306b\u300c\u3044\u305a\u308c\u304b\u306e\u9805\u76ee\u304c\u5fc5\u9808\u300d\u306e\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u5165\u308c\u305f<\/strong>\u3053\u3068\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u3053\u308c\u306b\u3088\u308a\u3001\u4ed6\u306e\u9805\u76ee\u306e\u5f71\u97ff\u3092\u53d7\u3051\u305a\u306b\u3001\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306e\u30c1\u30a7\u30c3\u30af\u304c\u884c\u3048\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u6700\u5f8c\u306b<\/h2>\n\n\n<p>\u3044\u304b\u304c\u3067\u3057\u305f\u3067\u3057\u3087\u3046\u304b\uff1f<\/p>\n<p>\u6a19\u6e96\u306b\u3042\u308a\u305d\u3046\u3067\u306a\u3044\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3067\u3059\u306d\u3002<\/p>\n<p>\u3082\u3057\u4ed6\u306b\u3082\u3063\u3068\u3044\u3044\u65b9\u6cd5\u3042\u308b\uff01\u306a\u3069\u3042\u308a\u307e\u3057\u305f\u3089\u3001\u30b3\u30e1\u30f3\u30c8\u3057\u3066\u3044\u305f\u3060\u3051\u308b\u3068\u3042\u308a\u304c\u305f\u3044\u3067\u3059\u3002<\/p>\n<p>\u4ee5\u4e0a\u3001zend validate\u3067\u300c\u3044\u305a\u308c\u304b\u4e00\u3064\u3092\u5fc5\u9808\u306b\u3059\u308b\u300d\u306e\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306e\u66f8\u304d\u65b9\u3067\u3057\u305f\uff5e\u3002<\/p>","protected":false},"excerpt":{"rendered":"<p>\u3069\u3046\u3082\u3001kat\u3067\u3059\u3002 \u7a81\u7136\u3067\u3059\u304c\u3001zend validate\u3067\u3001\u3053\u3093\u306a\u3053\u3068\u601d\u3063\u305f\u308a\u3057\u307e\u305b\u3093\u304b\uff1f \u30fb\u8907\u6570\u306e\u5165\u529b\u9805\u76ee\u306e\u3046\u3061\u3001\u3069\u308c\u304b\u4e00\u3064\u3060\u3051\u3092\u5fc5\u9808\u306b\u3057\u305f\u3044\u3000\u203b\u9006\u306b\u8a00\u3046\u3068\u3001\u8907\u6570\u9805\u76ee\u306e\u5168\u3066\u304c\u7a7a\u3060\u3063\u305f\u3068\u304d\u3060\u3051\u30a8\u30e9\u30fc\u306b\u3057\u305f\u3044\u3002 \u305d\u3093\u306a<\/p>\n","protected":false},"author":1,"featured_media":418,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_locale":"","_original_post":"","_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[7,2],"tags":[36,35,37],"class_list":["post-310","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-zend","category-programing","tag-php","tag-zend","tag-37","ja"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/katblog.manadream.net\/wp-content\/uploads\/2018\/12\/zend.jpg","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/paUgnN-50","_links":{"self":[{"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/posts\/310"}],"collection":[{"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/comments?post=310"}],"version-history":[{"count":73,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/posts\/310\/revisions"}],"predecessor-version":[{"id":2609,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/posts\/310\/revisions\/2609"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/media\/418"}],"wp:attachment":[{"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/media?parent=310"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/categories?post=310"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/tags?post=310"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}