{"id":657,"date":"2015-08-15T14:04:26","date_gmt":"2015-08-15T05:04:26","guid":{"rendered":"http:\/\/gomocool.net\/gomokulog\/?p=657"},"modified":"2015-08-23T17:22:48","modified_gmt":"2015-08-23T08:22:48","slug":"cakephp3-setter%e3%82%bb%e3%83%83%e3%82%bf%e3%83%bc%e3%81%a8getter%e3%82%b2%e3%83%83%e3%82%bf%e3%83%bc%e3%82%92%e3%81%96%e3%81%a3%e3%81%8f%e3%82%8a%e3%81%a8%e7%9f%a5%e3%82%8b%e3%80%82","status":"publish","type":"post","link":"https:\/\/gomokulog.gomocool.net\/?p=657","title":{"rendered":"[CakePHP3] Setter(\u30bb\u30c3\u30bf\u30fc)\u3068Getter(\u30b2\u30c3\u30bf\u30fc)\u3092\u3056\u3063\u304f\u308a\u3068\u77e5\u308b\u3002"},"content":{"rendered":"<p><a href=\"http:\/\/gomocool.net\/gomokulog\/?p=640\">\u524d\u56de<\/a>\u3001CakePHP3\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u3001\u304a\u305f\u3081\u306b\u3057\u306b\u30e6\u30fc\u30b6\u30fc\u7ba1\u7406\u3092\u4f5c\u3063\u305f\u304c\u3001\u30d1\u30b9\u30ef\u30fc\u30c9\u304c\u4e38\u898b\u3048\u3060\u3063\u305f\u3002<\/p>\n<p>\u306a\u306e\u3067\u3001\u6b21\u306f\u30d1\u30b9\u30ef\u30fc\u30c9\u306e\u6697\u53f7\u5316\u3092\u884c\u3046\u3002<\/p>\n<p>\u307e\u305a\u3001Model\u306eEntity\u306eUser.php\u3092\u958b\u304f\u3002<\/p>\n<p>\u3093\u3067\u3001\u30af\u30e9\u30b9\u4e0a\u90e8\u306buse\u53e5\u3067\u3001\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u30cf\u30c3\u30b7\u30e5\u5316\u3059\u308b\u30af\u30e9\u30b9\u306enamespace\u3092\u8ffd\u52a0\u3002<\/p>\n<pre class=\"lang:php decode:true \">namespace App\\Model\\Entity;\r\n\r\nuse Cake\\Auth\\DefaultPasswordHasher; \/\/\u3053\u308c\u3092\u8ffd\u52a0\r\nuse Cake\\ORM\\Entity;\r\n<\/pre>\n<p>\u306a\u3093\u3060\u304b\u3001C#\u306a\u611f\u3058\u306b\u306a\u3063\u305f\u306a\uff5e\u3002<br \/>\nuse \u3067\u30af\u30e9\u30b9\u3092\u6307\u5b9a\u3059\u308b\u304b\u3089\u3001NetBeans\u541b\u3067\u30b3\u30fc\u30c9\u88dc\u5b8c\u304c\u6c17\u6301\u3061\u3044\u3044\u3002<\/p>\n<p>C#\u3067\u66f8\u304f\u3068\u3001\u3053\u3093\u306a\u611f\u3058\u304b\u306a\u3002<\/p>\n<pre class=\"lang:c# decode:true\">using Cake.Auth.DefaultPasswordHasher;\r\nusing Cake.ORM.Entity;\r\n\r\nnamespace App.Model.Entity{\r\n    class User : Entity{\r\n       ....\r\n    }\r\n}<\/pre>\n<p>\u8131\u7dda\u3057\u305f\u3002<\/p>\n<p>\u3093\u3067\u3001\u4ee5\u4e0b\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n<pre class=\"lang:php decode:true\">\/**\r\n * \u30d1\u30b9\u30ef\u30fc\u30c9\u30bb\u30c3\u30bf\u30fc password\u306b\u5024\u3092\u30bb\u30c3\u30c8\u3059\u308b\u3068\u304d\u30cf\u30c3\u30b7\u30e5\u5316\u3059\u308b\u3002\r\n * @param type $value\r\n * @return type\r\n *\/\r\nprotected function _setPassword($value)\r\n{\r\n\t$hasher = new DefaultPasswordHasher();\r\n\treturn $hasher-&gt;hash($value);\r\n}<\/pre>\n<p>\u4e0a\u8a18\u306f\u3001password\u3068\u3044\u3046\u30ab\u30e9\u30e0\u540d\u3092\u30bb\u30c3\u30c8\u3059\u308b\u969b\u306b\u3001\u3053\u306e\u30bb\u30c3\u30bf\u30fc\u3092\u901a\u308a\u3001$value\u306b\u3042\u308b\u5024\u3092\u30cf\u30c3\u30b7\u30e5\u30af\u30e9\u30b9\u3067\u30cf\u30c3\u30b7\u30e5\u5316\u3057\u305f\u5024\u3092\u623b\u3059\u3053\u3068\u3067\u3001save\u3055\u308c\u308b\u969b\u306b\u3001\u7d50\u679c\u7684\u306b\u305d\u306e\u6697\u53f7\u5316\u3055\u308c\u305f\u5024\u304c\u4fdd\u5b58\u3055\u308c\u308b\u3002<\/p>\n<p>\u3053\u308c\u306f\u3001CakePHP3\u3067\u30bb\u30c3\u30bf\u30fc(Setter)\u3068\u547c\u3070\u308c\u308b\u6a5f\u80fd\u3067\u3001\u547d\u540d\u898f\u5247\u306b\u57fa\u3065\u3044\u3066\u3044\u308b\u30ab\u30e9\u30e0\u540d\u3092CameCase\u3067\u7d10\u4ed8\u3051\u3066\u3001\u30c7\u30fc\u30bf\u3092\u30bb\u30c3\u30c8\u3059\u308b\u969b\u306b\u52a0\u5de5\u3059\u308b\u3063\u307d\u3044\u3002<br \/>\n\u4e2d\u8eab\u3061\u3089\u3063\u3068\u8ffd\u3044\u304b\u3051\u305f\u3089\u3001\u305d\u308c\u3063\u307d\u3044\u6240\u304c\u3042\u3063\u305f\u3002<\/p>\n<pre class=\"lang:php decode:true\">$setter = '_set' . Inflector::camelize($p);\r\nif ($this-&gt;_methodExists($setter)) {\r\n    $value = $this-&gt;{$setter}($value);\r\n}\r\n$this-&gt;_properties[$p] = $value;<\/pre>\n<p>\u3053\u308c\u3067\u3001\u8a66\u3057\u306b\u5225\u306e\u30e6\u30fc\u30b6\u30fc\u3092\u4f5c\u6210\u3057\u305f\u3089\u3001\u3061\u3083\u3093\u3068\u30d1\u30b9\u30ef\u30fc\u30c9\u306f\u30cf\u30c3\u30b7\u30e5\u5316\u3055\u308c\u3066\u3044\u305f\u3002<br \/>\n\u30ef\u30fc\u30c9\u30e9\u30c3\u30d7\u304c\u50cd\u3044\u3066\u3001\u306f\u307f\u51fa\u3057\u307e\u304f\u3063\u3066\u308b\u3051\u3069(^^;)<\/p>\n<p><a href=\"http:\/\/gomocool.net\/gomokulog\/wp-content\/uploads\/2015\/08\/CakePHP3-2-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-658\" src=\"http:\/\/gomocool.net\/gomokulog\/wp-content\/uploads\/2015\/08\/CakePHP3-2-1.png\" alt=\"CakePHP3-2-1\" width=\"600\" height=\"131\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>\u4f3c\u305f\u3088\u3046\u306a\u611f\u3058\u3067\u3001<span class=\"lang:default decode:true  crayon-inline \">$method = &#8216;_get&#8217; . Inflector::camelize($property);<\/span> \u3068\u3044\u3046\u8a18\u8ff0\u3092\u898b\u304b\u3051\u305f\u306e\u3067\u3001\u30b2\u30c3\u30bf\u30fc(Getter)\u3082\u3042\u308b\u306a\u3068\u601d\u3044\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306a\u30e1\u30bd\u30c3\u30c9\u3092\u8ffd\u52a0\u3002<\/p>\n<pre class=\"lang:php decode:true\">protected function _getId($value)\r\n{\r\n\t$value = $value * 100;\r\n\treturn $value;\r\n}<\/pre>\n<p>\u8aad\u307f\u8fbc\u307f\u306a\u304a\u3057\u3066\u307f\u308b\u3068\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306bid\u304c\u3059\u3079\u3066100\u500d\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u3002<br \/>\n<a href=\"http:\/\/gomocool.net\/gomokulog\/wp-content\/uploads\/2015\/08\/CakePHP3-2-2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-659\" src=\"http:\/\/gomocool.net\/gomokulog\/wp-content\/uploads\/2015\/08\/CakePHP3-2-2.png\" alt=\"CakePHP3-2-2\" width=\"197\" height=\"148\" \/><\/a><\/p>\n<p>\u4ee5\u4e0a\u3001CakePHP3\u306e\u30b2\u30c3\u30bf\u30fc(Getter)\u3068\u30bb\u30c3\u30bf\u30fc(Setter)\u306a\u304a\u8a71\u3002<\/p>\n<p>\u30d1\u30b9\u30ef\u30fc\u30c9\u306e\u30cf\u30c3\u30b7\u30e5\u5316\u3082\u3067\u304d\u305f\u306e\u3067\u3001\u6b21\u306fForm\u3067\u30e6\u30fc\u30b6\u30fc\u8a8d\u8a3c\u3057\u3066\u307f\u308b\u3002 &gt;&gt; <a href=\"http:\/\/gomocool.net\/gomokulog\/?p=664\">[CakePHP3] \u3056\u3063\u304f\u308a\u3068\u30d5\u30a9\u30fc\u30e0\u8a8d\u8a3c<\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u56de\u3001CakePHP3\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u3001\u304a\u305f\u3081\u306b\u3057\u306b\u30e6\u30fc\u30b6\u30fc\u7ba1\u7406\u3092\u4f5c\u3063\u305f\u304c\u3001\u30d1\u30b9\u30ef\u30fc\u30c9\u304c\u4e38\u898b\u3048\u3060\u3063\u305f\u3002 \u306a\u306e\u3067\u3001\u6b21\u306f\u30d1\u30b9\u30ef\u30fc\u30c9\u306e\u6697\u53f7\u5316\u3092\u884c\u3046\u3002 \u307e\u305a\u3001Model\u306eEntity\u306eUser.php\u3092\u958b\u304f\u3002 \u3093\u3067\u3001\u30af\u30e9\u30b9\u4e0a\u90e8&hellip;  <a href=\"https:\/\/gomokulog.gomocool.net\/?p=657\" class=\"more-link\">more <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[56],"tags":[],"class_list":["post-657","post","type-post","status-publish","format-standard","hentry","category-cakephp3"],"_links":{"self":[{"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=\/wp\/v2\/posts\/657","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=657"}],"version-history":[{"count":5,"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=\/wp\/v2\/posts\/657\/revisions"}],"predecessor-version":[{"id":675,"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=\/wp\/v2\/posts\/657\/revisions\/675"}],"wp:attachment":[{"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=657"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=657"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=657"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}