{"id":689,"date":"2020-10-19T08:32:07","date_gmt":"2020-10-19T00:32:07","guid":{"rendered":"https:\/\/www.cxybj.com\/?p=689"},"modified":"2020-10-19T08:33:09","modified_gmt":"2020-10-19T00:33:09","slug":"thinkphp6-%e6%8c%87%e4%bb%a4%e5%bf%ab%e9%80%9f%e7%94%9f%e6%88%90%e9%aa%8c%e8%af%81%e5%99%a8%e5%ae%9a%e4%b9%89","status":"publish","type":"post","link":"https:\/\/www.cxybj.com\/?p=689","title":{"rendered":"Thinkphp6 \u6307\u4ee4\u5feb\u901f\u751f\u6210validate\u9a8c\u8bc1\u5668"},"content":{"rendered":"<p>\u4e3a\u5177\u4f53\u7684\u9a8c\u8bc1\u573a\u666f\u6216\u8005\u6570\u636e\u8868\u5b9a\u4e49\u597d\u9a8c\u8bc1\u5668\u7c7b\uff0c\u76f4\u63a5\u8c03\u7528\u9a8c\u8bc1\u7c7b\u7684check\u65b9\u6cd5\u5373\u53ef\u5b8c\u6210\u9a8c\u8bc1\uff0c\u4e0b\u9762\u662f\u4e00\u4e2a\u4f8b\u5b50\uff1a<\/p>\n<p>\u6211\u4eec\u5b9a\u4e49\u4e00\u4e2a\\app\\validate\\User\u9a8c\u8bc1\u5668\u7c7b\u7528\u4e8eUser\u7684\u9a8c\u8bc1\u3002<\/p>\n<p>namespace app\\validate;<br \/>\nuse think\\Validate;<br \/>\nclass User extends Validate {<br \/>\nprotected $rule = [<br \/>\n&#8216;name&#8217; =&gt; &#8216;require|max:25&#8242;,<br \/>\n&#8217;email&#8217; =&gt; &#8217;email&#8217;,<br \/>\n]; }<\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528\u4e0b\u9762\u7684\u6307\u4ee4\u5feb\u901f\u751f\u6210<code>User<\/code>\u9a8c\u8bc1\u5668:<br \/>\nphp think make:validate User<br \/>\n\u751f\u6210\u540e\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<p>&lt;?php<br \/>\nnamespace app\\controller;<br \/>\nuse app\\validate\\User;<br \/>\nuse think\\exception\\ValidateException;<br \/>\nclass Index {<br \/>\npublic function index() {<br \/>\ntry { validate(User::class)-&gt;check([<br \/>\n&#8216;name&#8217; =&gt; &#8216;thinkphp&#8217;,<br \/>\n&#8217;email&#8217; =&gt; &#8216;thinkphp@qq.com&#8217;,<br \/>\n]); } catch (ValidateException $e) { \/\/ \u9a8c\u8bc1\u5931\u8d25 \u8f93\u51fa\u9519\u8bef\u4fe1\u606f<br \/>\ndump($e-&gt;getError());<br \/>\n}<br \/>\n}<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e3a\u5177\u4f53\u7684\u9a8c\u8bc1\u573a\u666f\u6216\u8005\u6570\u636e\u8868\u5b9a\u4e49\u597d\u9a8c\u8bc1\u5668\u7c7b\uff0c\u76f4\u63a5\u8c03\u7528\u9a8c\u8bc1\u7c7b\u7684c &hellip; <a href=\"https:\/\/www.cxybj.com\/?p=689\" class=\"more-link\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2,133],"tags":[],"_links":{"self":[{"href":"https:\/\/www.cxybj.com\/index.php?rest_route=\/wp\/v2\/posts\/689"}],"collection":[{"href":"https:\/\/www.cxybj.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cxybj.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cxybj.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cxybj.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=689"}],"version-history":[{"count":2,"href":"https:\/\/www.cxybj.com\/index.php?rest_route=\/wp\/v2\/posts\/689\/revisions"}],"predecessor-version":[{"id":691,"href":"https:\/\/www.cxybj.com\/index.php?rest_route=\/wp\/v2\/posts\/689\/revisions\/691"}],"wp:attachment":[{"href":"https:\/\/www.cxybj.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=689"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cxybj.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=689"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cxybj.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=689"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}