{"id":245,"date":"2014-05-17T14:11:18","date_gmt":"2014-05-17T05:11:18","guid":{"rendered":"http:\/\/gomocool.net\/gomokulog\/?p=245"},"modified":"2014-05-17T14:11:18","modified_gmt":"2014-05-17T05:11:18","slug":"cakephp2-%e3%81%96%e3%81%a3%e3%81%8f%e3%82%8a%e3%81%a8%e3%83%99%e3%83%bc%e3%82%b7%e3%83%83%e3%82%af%e8%aa%8d%e8%a8%bc","status":"publish","type":"post","link":"https:\/\/gomokulog.gomocool.net\/?p=245","title":{"rendered":"CakePHP2 \u3056\u3063\u304f\u308a\u3068\u30d9\u30fc\u30b7\u30c3\u30af\u8a8d\u8a3c"},"content":{"rendered":"<p>CakePHP2.4\u3067\u3001\u898b\u305b\u305f\u304f\u306a\u3044\u30da\u30fc\u30b8\u306b\u3061\u3087\u3063\u3068\u30d9\u30fc\u30b7\u30c3\u30af\u8a8d\u8a3c\u3092\u639b\u3051\u305f\u304b\u3063\u305f\u3060\u3051\u306a\u306e\u306b\u3001\u5999\u306b\u30cf\u30de\u3063\u305f\u3002<br \/>\n\u300cCakePHP2\u3067\u306f\u3001\u7c21\u5358\u306b\u30d9\u30fc\u30b7\u30c3\u30af\u8a8d\u8a3c\u3092\u304b\u3051\u308c\u308b\u3002\u300d\u3089\u3057\u3044\u306e\u306b\u30fb\u30fb\u30fb\u3002<br \/>\n\u5b9f\u969b\u3001\u306a\u3093\u3068\u3044\u3046\u3053\u3068\u306f\u306a\u304b\u3063\u305f\u304c\u3001\u4ed6\u306e\u8a8d\u8a3c\u306e\u60c5\u5831\u3068\u304b\u3001CakePHP1\u3068\u52d8\u9055\u3044\u3057\u305f\u308a\u3067\u3001\u30cf\u30de\u3063\u305f\u3002<\/p>\n<p>\u3055\u3066\u3001CakePHP2\u3067\u306e\u30d9\u30fc\u30b7\u30c3\u30af\u8a8d\u8a3c\u3060\u304c\u3001\u30b9\u30c6\u30c3\u30d7\u306f\u4ee5\u4e0b\u306e\u3068\u304a\u308a\u3002<\/p>\n<ol>\n<li>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306busers\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u308b\u3002<\/li>\n<li>users\u30c6\u30fc\u30d6\u30eb\u306b\u5bfe\u5fdc\u3057\u305fUser\u30e2\u30c7\u30eb\u3092\u4f5c\u308b\u3002<\/li>\n<li>User\u30e2\u30c7\u30eb\u306b\u5bfe\u5fdc\u3057\u305fUsersContoller\u3092\u4f5c\u3063\u3066\u3001\u30e6\u30fc\u30b6\u30fc\u3092\u4f5c\u308b\u3002<\/li>\n<li>\u898b\u305b\u305f\u304f\u306a\u3044\u30da\u30fc\u30b8\u306bAuth\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3067Basic\u3092\u304b\u3051\u308b\u3002<\/li>\n<\/ol>\n<p>\u3068\u308a\u3042\u3048\u305a\u3001\u624b\u9806\u3092\u3056\u3063\u304f\u308a\u8a18\u8ff0\u3057\u3066\u3044\u304f\u3002<\/p>\n<h2>1.\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306busers\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u308b\u3002<\/h2>\n<p>\u3053\u3093\u306a\u304b\u3093\u3058\u304b\u306a\u3002<\/p>\n<pre class=\"lang:mysql decode:true\">CREATE TABLE IF NOT EXISTS users(\r\nid bigint unsigned PRIMARY KEY AUTO_INCREMENT ,\r\nusername varchar( 256 ) NOT NULL ,\r\npassword varchar( 256 ) NOT NULL ,\r\ncreated datetime NOT NULL ,\r\nmodified datetime NOT NULL\r\n) ENGINE = InnoDB DEFAULT CHARSET = utf8<\/pre>\n<p>\u30ab\u30e9\u30e0\u540d\u306f\u7279\u306b\u7406\u7531\u304c\u306a\u3044\u304b\u304e\u308a\u5909\u66f4\u305b\u305a\u306b\u3001username\u3068password\u3067\u306b\u3057\u3066\u304a\u304f\u3068\u826f\u3044\u3002<br \/>\ncreated\u3068modifed\u3082\u3001\u3068\u308a\u3042\u3048\u305a\u4e00\u7dd2\u3064\u3051\u3068\u3051\u3070Cake\u304c\u52dd\u624b\u306b\u4f7f\u3046\u306e\u3067\u3001\u5165\u308c\u304a\u304f\u3002<\/p>\n<p>\u3053\u308c\u3067\u3001\u30e6\u30fc\u30b6\u30fc\u3092\u7ba1\u7406\u3059\u308b\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u308b\u3002<\/p>\n<h2>2.users\u30c6\u30fc\u30d6\u30eb\u306b\u5bfe\u5fdc\u3057\u305fUser\u30e2\u30c7\u30eb\u3092\u4f5c\u308b\u3002<\/h2>\n<p>\u3055\u3066\u3001\u6b21\u306b\u5bfe\u5fdc\u3059\u308b\u30e2\u30c7\u30eb\u3092\u4f5c\u308b\u3002<\/p>\n<pre class=\"lang:php decode:true\">&lt;?php\r\nApp::uses('AuthComponent', 'Controller\/Component');\r\nclass User extends AppModel {\r\n    public function beforeSave($options = array()) {\r\n        $this-&gt;data['User']['password'] = AuthComponent::password($this-&gt;data['User']['password']);\r\n        \/\/parent::beforeSave($options);\r\n        return true;\r\n    }\r\n}<\/pre>\n<p>\u3053\u3093\u306a\u611f\u3058\u3002<\/p>\n<p>\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u305d\u306e\u307e\u307e\u4fdd\u5b58\u305b\u305a\u306b\u3001\u6697\u53f7\u5316(\u30cf\u30c3\u30b7\u30e5\u5316)\u3057\u3066\u4fdd\u5b58\u3059\u308b\u3002<br \/>\nAuthComponent::password \u3092\u4f7f\u3048\u3070\u3001\u30cf\u30c3\u30b7\u30e5\u5316\u3055\u308c\u3066\u30d1\u30b9\u30ef\u30fc\u30c9\u306f\u4fdd\u5b58\u3055\u308c\u308b\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>3.User\u30e2\u30c7\u30eb\u306b\u5bfe\u5fdc\u3057\u305fUsersContoller\u3092\u4f5c\u3063\u3066\u3001\u30e6\u30fc\u30b6\u30fc\u3092\u4f5c\u308b\u3002<\/h2>\n<p>\u3055\u3066\u3001\u6b21\u306b\u30ed\u30b0\u30a4\u30f3\u3059\u308b\u30e6\u30fc\u30b6\u30fc\u3092\u4f5c\u6210\u3059\u308b\u305f\u3081\u306b\u3001User\u30e2\u30c7\u30eb\u3092\u6271\u3046\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3092\u4f5c\u6210\u3059\u308b\u3002<\/p>\n<p>\u30e6\u30fc\u30b6\u30fc\u304c\u3044\u306a\u3044\u3068\u305d\u3082\u305d\u3082\u30ed\u30b0\u30a4\u30f3\u3067\u304d\u306a\u3044\u3057\u306d\u3002<\/p>\n<p>\u4ee5\u4e0b\u306e\u69d8\u306a\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3092\u4f5c\u308b\u3002<\/p>\n<pre class=\"lang:php decode:true\">&lt;?php\r\n\r\nclass UsersController  extends AppController{\r\n    public $scaffold = \"\";\r\n}<\/pre>\n<p>User\u30e2\u30c7\u30eb\u3092\u6271\u3046UsersController\u3092\u4f5c\u6210\u3057\u3001\u5909\u6570\u540d$scaffold\u3092\u5ba3\u8a00\u3002<br \/>\n\u3042\u3068\u306f\u3001\u3053\u306e\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308c\u3070\u3001users\u30c6\u30fc\u30d6\u30eb\u3092\u6271\u3046\u8af8\u3005\u304c\u3067\u304d\u3066\u3044\u308b\u306f\u305a\u306a\u306e\u3067\u3001\u305d\u3053\u3067\u30e6\u30fc\u30b6\u30fc\u3092\u4f5c\u6210\u3059\u308b\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>4.\u898b\u305b\u305f\u304f\u306a\u3044\u30da\u30fc\u30b8\u306bAuth\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3067Basic\u3092\u304b\u3051\u308b\u3002<\/h2>\n<p>\u3055\u3066\u3001\u3044\u3088\u3044\u3088\u672c\u984c\u306b\u306a\u308b\u3002<\/p>\n<p>\u30d9\u30fc\u30b7\u30c3\u30af\u8a8d\u8a3c\u3092\u304b\u3051\u305f\u3044\u30da\u30fc\u30b8\u306b\u3001Auth\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u8aad\u307f\u8fbc\u307f\u3093\u3067\u3001beforeFilter\u3067\u5272\u308a\u4ed8\u3051\u308b\u3002<\/p>\n<pre class=\"lang:php decode:true\">class HogeController extends AppController{\r\n    public $components = array('Session','Auth');\r\n    \r\n    public function beforeFilter() { \r\n        parent::beforeFilter();\r\n        \r\n        \/\/Basic Auth\r\n        $this-&gt;Auth-&gt;authenticate = array('Basic');\r\n    }<\/pre>\n<p>\u3053\u308c\u3067\u3001Hoge\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u306b\u306f\u30d9\u30fc\u30b7\u30c3\u30af\u8a8d\u8a3c\u304c\u304b\u304b\u308b\u3002<\/p>\n<p>\u30b5\u30a4\u30c8\u5168\u4f53\u306b\u304b\u3051\u305f\u3051\u308c\u3070\u3001AppController\u306ebeforeFilter\u306b\u540c\u3058\u3088\u3046\u306b\u66f8\u3051\u3070\u826f\u3044\u3002<\/p>\n<p>\u3082\u3057\u3001\u57fa\u672c\u898b\u305b\u3066\u3082\u3044\u3044\u304c\u3001\u7ba1\u7406\u30da\u30fc\u30b8\u306f\u898b\u305b\u305f\u304f\u306a\u3044\u3063\u3066\u5834\u5408\u306f\u3001<\/p>\n<pre class=\"lang:php decode:true\">&lt;?php\r\nclass ManagerAppController extends AppController {\r\n    \r\n    public $components = array('Session','Auth');\r\n    \r\n    public function beforeFilter() {\r\n        parent::beforeFilter();\r\n        \r\n        \/\/Basic Auth\r\n        $this-&gt;Auth-&gt;authenticate = array('Basic');   \r\n\r\n    }\r\n}<\/pre>\n<p>\u3053\u3093\u306a\u98a8\u306b\u3001AppController\u3092\u7d99\u627f\u3057\u3066\u3082\u3046\u4e00\u3064\u4f5c\u3063\u305f\u3082\u306e\u3092\u7d99\u627f\u3057\u305f\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u306b\u3059\u308c\u3070\u3088\u3044\u3068\u601d\u3046\u30fb\u30fb\u30fb\u3002<br \/>\n(\u4ed6\u306b\u3001\u3084\u308a\u65b9\u3042\u308b\u3089\u3057\u3044\u3051\u3069\u3002)<\/p>\n<p>\u3061\u306a\u307f\u306b\u3001\u30d9\u30fc\u30b7\u30c3\u30af\u8a8d\u8a3c\u306f\u5e73\u6587\u3067\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u9001\u308b\u3089\u3057\u3044\u306e\u3067\u3001\u9001\u4fe1\u7d4c\u7531\u3067\u76d7\u8074\u3055\u308c\u308b\u3068\u3001\u305d\u306e\u307e\u307e\u30d1\u30b9\u30ef\u30fc\u30c9\u304c\u898b\u3089\u308c\u308b\u3089\u3057\u3044\u3002<br \/>\n\u307e\u3041\u3001\u591a\u304f\u306e\u4eba\u304c\u3001\u30c9\u30a2\u304c\u9589\u307e\u3063\u3066\u308c\u3070\u30ac\u30e9\u30b9\u3092\u5272\u3063\u3066\u5165\u308d\u3046\u3068\u306f\u601d\u308f\u306a\u3044\u306e\u3067\u3001\u306a\u3044\u3088\u308a\u306f\u30de\u30b7\u3060\u3068\u601d\u3046\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>CakePHP2.4\u3067\u3001\u898b\u305b\u305f\u304f\u306a\u3044\u30da\u30fc\u30b8\u306b\u3061\u3087\u3063\u3068\u30d9\u30fc\u30b7\u30c3\u30af\u8a8d\u8a3c\u3092\u639b\u3051\u305f\u304b\u3063\u305f\u3060\u3051\u306a\u306e\u306b\u3001\u5999\u306b\u30cf\u30de\u3063\u305f\u3002 \u300cCakePHP2\u3067\u306f\u3001\u7c21\u5358\u306b\u30d9\u30fc\u30b7\u30c3\u30af\u8a8d\u8a3c\u3092\u304b\u3051\u308c\u308b\u3002\u300d\u3089\u3057\u3044\u306e\u306b\u30fb\u30fb\u30fb\u3002 \u5b9f\u969b\u3001\u306a\u3093\u3068\u3044\u3046\u3053\u3068\u306f\u306a\u304b\u3063\u305f\u304c\u3001&hellip;  <a href=\"https:\/\/gomokulog.gomocool.net\/?p=245\" 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":[68,9],"tags":[21,62,38],"class_list":["post-245","post","type-post","status-publish","format-standard","hentry","category-cakephp","category-php","tag-cakephp","tag-php","tag-38"],"_links":{"self":[{"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=\/wp\/v2\/posts\/245","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=245"}],"version-history":[{"count":3,"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=\/wp\/v2\/posts\/245\/revisions"}],"predecessor-version":[{"id":248,"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=\/wp\/v2\/posts\/245\/revisions\/248"}],"wp:attachment":[{"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=245"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=245"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=245"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}