{"id":1290,"date":"2021-01-30T19:47:48","date_gmt":"2021-01-30T10:47:48","guid":{"rendered":"https:\/\/tech.at-iroha.jp\/?p=1290"},"modified":"2026-03-12T15:57:43","modified_gmt":"2026-03-12T06:57:43","slug":"cakephp-2-x-%e3%81%8b%e3%82%89-cakephp-4-x-%e3%81%b8%e3%81%ae%e7%a7%bb%e8%a1%8c%e3%81%ab%e3%81%a4%e3%81%84%e3%81%a6-1","status":"publish","type":"post","link":"https:\/\/tech.at-iroha.jp\/?p=1290","title":{"rendered":"CakePHP2 \u304b\u3089 CakePHP4 \u3078\u306e\u79fb\u884c\u306b\u3064\u3044\u3066 (1)"},"content":{"rendered":"\n<p>\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306e\u30a2\u30c3\u30d7\u30b0\u30ec\u30fc\u30c9\u306f\u3001\u3057\u3070\u3057\u3070\u958b\u767a\u8005\u306b\u3068\u3063\u3066\u982d\u306e\u75db\u3044\u554f\u984c\u3068\u306a\u3063\u3066\u3044\u307e\u3059\u3002\u4eca\u56de\u306f\u6050\u3089\u304f\u591a\u304f\u306e\u7d44\u7e54\u3067\u8ab2\u984c\u3068\u306a\u3063\u3066\u3044\u308b\u3068\u601d\u308f\u308c\u308b CakePHP2 \u304b\u3089 CakePHP4 \u3078\u79fb\u884c\u306b\u3064\u3044\u3066\u53d6\u308a\u4e0a\u3052\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"iroha-comment\">\u5c0f\u898f\u6a21\u304b\u3064CakePHP2\u7248\u306e\u30bd\u30fc\u30b9\u306e\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u306e\u7d99\u7d9a\u3092\u524d\u63d0\u3068\u3057\u305f\u30bd\u30d5\u30c8\u30a6\u30a7\u30a2\u3092\u79fb\u884c\u5bfe\u8c61\u3068\u3057\u3066\u304a\u308a\u3001\u4ed6\u306e\u30b7\u30b9\u30c6\u30e0\u306e\u79fb\u884c\u306b\u5bfe\u3057\u3066\u306f\u3042\u307e\u308a\u53c2\u8003\u306b\u306a\u3089\u306a\u3044\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002\u307e\u305f\u30d3\u30d8\u30a4\u30d3\u30a2\u3001\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3001\u30d8\u30eb\u30d1\u30fc\u3001\u30d7\u30e9\u30b0\u30a4\u30f3\u3001\u30b7\u30a7\u30eb\u3001\u30c6\u30b9\u30c8\u306f\u79fb\u884c\u5bfe\u8c61\u3068\u3057\u3066\u3044\u307e\u305b\u3093\u3002\u8a18\u8f09\u3057\u3066\u3044\u308b\u30b3\u30fc\u30c9\u306f\u4e8b\u524d\u8abf\u67fb\u306e\u305f\u3081\u306b\u72ec\u81ea\u306b\u4f5c\u6210\u3057\u305f\u3082\u306e\u3067\u3001\u52d5\u4f5c\u3092\u4fdd\u8a3c\u3059\u308b\u3082\u306e\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u80cc\u666f<\/h2>\n\n\n\n<p>CakePHP \u306f Ruby on Rails \u306eMVC\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u306e\u5f71\u97ff\u3092\u5f37\u304f\u53d7\u3051\u305fWeb\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3067\u3001\u30b3\u30df\u30e5\u30cb\u30c6\u30a3\u3082\u6d3b\u767a\u3067\u56fd\u5185\u3067\u306f\u3068\u3066\u3082\u4eba\u6c17\u304c\u3042\u308a\u307e\u3059\u3002\u8fd1\u5e74\u3001PHP\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3068\u3057\u3066\u306f Laravel \u304c\u6700\u3082\u4eba\u6c17\u3068\u306a\u3063\u3066\u3044\u307e\u3059\u304c\u3001\u56fd\u5185\u306e\u904b\u7528\u4e2d\u306eWeb\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u63a1\u7528\u6570\u3067\u306f\u73fe\u5728\u3082CakePHP \u304c\u4e0a\u56de\u3063\u3066\u3044\u308b\u3068\u8a00\u308f\u308c\u3066\u3044\u307e\u3059\u3002\u305f\u3060 CakePHP \u306f 3.0 \u3067\u5225\u306e\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3068\u547c\u3079\u308b\u3050\u3089\u3044\u5927\u304d\u306a\u4ed5\u69d8\u5909\u66f4\u304c\u884c\u308f\u308c\u3001\u30b9\u30e0\u30fc\u30ba\u306b\u79fb\u884c\u304c\u9032\u307e\u305a\u3001\u307e\u3060\u591a\u304f\u306e\u30b5\u30a4\u30c8\u3067 CakePHP2 \u304c\u4f7f\u7528\u3055\u308c\u3066\u3044\u308b\u3068\u601d\u308f\u308c\u307e\u3059\u3002 <\/p>\n\n\n\n<p>2015\u5e74\u9803\u306bMVC\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306e\u52c9\u5f37\u3082\u517c\u306d\u3066\u3001CakePHP2 \u3092\u30d9\u30fc\u30b9\u306b\u4e00\u4eba\u3067\u30b7\u30f3\u30d7\u30eb\u306ae\u30e9\u30fc\u30cb\u30f3\u30b0\u30b7\u30b9\u30c6\u30e0\u3092\u958b\u767a\u3057\u3001\u30aa\u30fc\u30d7\u30f3\u30bd\u30fc\u30b9\u5316\u3057\u307e\u3057\u305f\u3002\u30ea\u30ea\u30fc\u30b9\u5f8c\u3001\u5927\u304d\u306a\u53cd\u97ff\u304c\u3042\u308a\u3001\u65e2\u306b\u591a\u304f\u306e\u7d44\u7e54\u5185\u306ee\u30e9\u30fc\u30cb\u30f3\u30b0\u3067\u6d3b\u7528\u3055\u308c\u3001\u73fe\u5728\u3082\u983b\u7e41\u306b\u30d0\u30fc\u30b8\u30e7\u30f3\u30a2\u30c3\u30d7\u3092\u884c\u3063\u3066\u3044\u307e\u3059\u3002CakePHP2 \u306f\u30b3\u30f3\u30d1\u30af\u30c8\u3067\u3068\u3066\u3082\u3088\u304f\u3067\u304d\u305f\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3067\u3001\u53ef\u80fd\u306a\u9650\u308a\u3053\u306e\u307e\u307e\u5229\u7528\u3057\u3066\u3044\u304d\u305f\u3044\u3068\u8003\u3048\u3066\u3044\u307e\u3057\u305f\u304c\u3001CakePHP \u30b3\u30df\u30e5\u30cb\u30c6\u30a3\u3088\u308b\u30b5\u30dd\u30fc\u30c8\u306e\u7d42\u4e86\u304c\u767a\u8868\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u3082\u3042\u308a\u3001CakePHP4 \u3078\u306e\u79fb\u884c\u306e\u691c\u8a0e\u3092\u59cb\u3081\u308b\u3053\u3068\u3068\u3057\u307e\u3057\u305f\u3002\uff08\u3042\u304f\u307e\u3067\u3082\u4e8b\u524d\u8abf\u67fb\u3084\u5b9f\u9a13\u7684\u5b9f\u88c5\u306e\u6bb5\u968e\u3067\u3001\u79fb\u884c\u3092\u6c7a\u5b9a\u3057\u305f\u308f\u3051\u3067\u3042\u308a\u307e\u305b\u3093\u3002\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306b\u3053\u308c\u4ee5\u4e0a\u306e\u6a5f\u80fd\u3092\u6c42\u3081\u3066\u3044\u306a\u3044\u305f\u3081\u3001CakePHP2 \u304b\u3089\u30d5\u30a9\u30fc\u30af\u3057\u3001\u72ec\u81ea\u306b\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u3059\u308b\u9053\u3082\u3042\u308b\u3068\u8003\u3048\u3066\u3044\u307e\u3059\u3002\uff09<\/p>\n\n\n\n<p>\u3061\u306a\u307f\u306b2015\u5e74\u306b\u3061\u3087\u3046\u3069 CakePHP 3.0 \u304c\u30ea\u30ea\u30fc\u30b9\u3055\u308c\u3001\u307e\u305f Laravel \u306e\u4eba\u6c17\u3082\u9ad8\u307e\u3063\u3066\u3044\u305f\u6642\u671f\u3067\u3057\u305f\u304c\u3001\u4ee5\u4e0b\u306e\u7406\u7531\u3067 CakePHP2 \u3092\u63a1\u7528\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>CakePHP 3.0 \u306e\u60c5\u5831\u304c\u5c11\u306a\u304f\u3001CakePHP 2.x \u304c\u4e3b\u6d41\u3067\u3042\u3063\u305f\u3002\u307e\u305f 3.x \u306f\u4eca\u5f8c\u3001\u4ed5\u69d8\u304c\u5927\u304d\u304f\u5909\u308f\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u3001\u5b89\u5b9a\u6027\u3092\u91cd\u8996\u3057\u305f\u3002<\/li>\n\n\n\n<li>CakePHP 3.0 \u306fPHP 5.4 \u4ee5\u4e0a\u3092\u5fc5\u9808\u3068\u3057\u3066\u3044\u305f\u3002\u958b\u767a\u3057\u305f\u30bd\u30d5\u30c8\u30a6\u30a7\u30a2\u306f\u5b89\u4fa1\u306a\u30ec\u30f3\u30bf\u30eb\u30b5\u30fc\u30d0\u306b\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3053\u3068\u3092\u524d\u63d0\u3068\u3057\u3066\u3044\u305f\u304c\u3001\u591a\u304f\u306e\u30ec\u30f3\u30bf\u30eb\u30b5\u30fc\u30d0\u304c\u307e\u3060PHP 5.3 \u3092\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u3068\u3057\u3066\u3044\u305f\u3002<\/li>\n\n\n\n<li>Laravel \u306f PHP 5.5 \u4ee5\u4e0a\u3092\u5fc5\u9808\u3068\u3057\u3066\u304a\u308a\u3001\u307e\u305f\u30b3\u30f3\u30d1\u30af\u30c8\u306a\u30bd\u30d5\u30c8\u30a6\u30a7\u30a2\u306b\u3068\u3063\u3066 Laravel \u306f\u30aa\u30fc\u30d0\u30fc\u30b9\u30da\u30c3\u30af\u3060\u3063\u305f\u3002\u307e\u305f CakePHP \u3068\u6bd4\u3079\u3066\u9032\u5316\u306e\u30b9\u30d4\u30fc\u30c9\u304c\u901f\u304f\u3001\u30b5\u30dd\u30fc\u30c8\u671f\u9593\u3082\u30ea\u30ea\u30fc\u30b9\u5f8c\u3001\u6570\u5e74\u7a0b\u5ea6\u3068\u77ed\u3044\u3002\uff08\u540c\u69d8\u306e\u7406\u7531\u3067\u3001\u4eca\u5f8c\u3082\u4e57\u308a\u63db\u3048\u3092\u4e88\u5b9a\u3057\u3066\u3044\u306a\u3044\u3002\uff09<\/li>\n<\/ol>\n\n\n\n<p>\u65e2\u306b CakePHP 4.1 \u3067\u8a66\u9a13\u7684\u306b\u5b9f\u88c5\u3092\u958b\u59cb\u3057\u3066\u304a\u308a\u3001\u4e00\u901a\u308a\u306e\u4ed5\u69d8\u306f\u628a\u63e1\u3067\u304d\u3066\u3044\u307e\u3059\u3002CakePHP2 \u3068 CakePHP4 \uff08CakePHP3\uff09\u306e\u4e3b\u306a\u9055\u3044\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/book.cakephp.org\/4\/ja\/installation.html\" data-type=\"URL\" data-id=\"https:\/\/book.cakephp.org\/4\/ja\/installation.html\" target=\"_blank\" rel=\"noreferrer noopener\">\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/a>\u3001\u30d1\u30c3\u30b1\u30fc\u30b8\u7ba1\u7406\u306b Composer \u3092\u63a1\u7528<\/li>\n\n\n\n<li>\u30aa\u30fc\u30c8\u30ed\u30fc\u30c9\uff08PSR-4\uff09\u306b\u5bfe\u5fdc<\/li>\n\n\n\n<li><a href=\"https:\/\/book.cakephp.org\/4\/ja\/intro\/cakephp-folder-structure.html\" data-type=\"URL\" data-id=\"https:\/\/book.cakephp.org\/4\/ja\/intro\/cakephp-folder-structure.html\" target=\"_blank\" rel=\"noreferrer noopener\">\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u69cb\u6210<\/a>\u306e\u5909\u66f4\uff08\u3088\u308a\u7d30\u5206\u5316\u3001\u30d3\u30e5\u30fc\u306e .ctp \u306f .php \u306b\uff09<\/li>\n\n\n\n<li>\u30e2\u30c7\u30eb\u3092\u69cb\u6210\u3059\u308b\u30af\u30e9\u30b9\u304c\u30c6\u30fc\u30d6\u30eb\u304b\u3089<a href=\"https:\/\/book.cakephp.org\/4\/ja\/orm\/entities.html\" data-type=\"URL\" data-id=\"https:\/\/book.cakephp.org\/4\/ja\/orm\/entities.html\" target=\"_blank\" rel=\"noreferrer noopener\">\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3<\/a>\u3068<a href=\"https:\/\/book.cakephp.org\/4\/ja\/orm\/table-objects.html\" data-type=\"URL\" data-id=\"https:\/\/book.cakephp.org\/4\/ja\/orm\/table-objects.html\" target=\"_blank\" rel=\"noreferrer noopener\">\u30c6\u30fc\u30d6\u30eb<\/a>\u306b\uff08ORM\u304c\u4e00\u65b0\uff09<\/li>\n\n\n\n<li>\u30e2\u30c7\u30eb\u304b\u3089\u53d6\u5f97\u3059\u308b\u30c7\u30fc\u30bf\u304c\u9023\u60f3\u914d\u5217\u304b\u3089<a href=\"https:\/\/book.cakephp.org\/4\/ja\/orm\/retrieving-data-and-resultsets.html\" target=\"_blank\" rel=\"noreferrer noopener\">\u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/a>\u306b<\/li>\n\n\n\n<li><a href=\"https:\/\/book.cakephp.org\/4\/ja\/controllers\/middleware.html\" target=\"_blank\" rel=\"noreferrer noopener\">\u30df\u30c9\u30eb\u30a6\u30a7\u30a2<\/a>\uff08PSR-7\uff09\u3092\u63a1\u7528<\/li>\n\n\n\n<li>\u69d8\u3005\u306a\u6a19\u6e96\u30af\u30e9\u30b9\u306e\u4ed5\u69d8\u5909\u66f4<\/li>\n<\/ul>\n\n\n\n<p>\u3067\u304d\u308b\u3053\u3068\u306b\u305d\u308c\u307b\u3069\u5927\u304d\u306a\u9055\u3044\u306f\u3042\u308a\u307e\u305b\u3093\u304c\u3001\u30e2\u30c7\u30eb\u5468\u308a\u306e\u7834\u58ca\u7684\u306a\u4ed5\u69d8\u5909\u66f4\u304c\u79fb\u884c\u306e\u969b\u3001\u4e00\u756a\u306e\u969c\u5bb3\u3068\u306a\u308b\u3068\u8003\u3048\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u79fb\u884c\u65b9\u91dd<\/h2>\n\n\n\n<p>\u79fb\u884c\u306f\u300c\u4e8b\u524d\u306e\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0\u300d\u3068\u300c\u30b3\u30f3\u30d0\u30fc\u30bf\u306e\u4f5c\u6210\u300d\u3092\u4e8c\u3064\u306e\u67f1\u3068\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u307e\u305a\u79fb\u884c\u524d\u306b\u3001CakePHP2 \u5074\u306e\u30bd\u30fc\u30b9\u3092\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0 \u306b\u3088\u3063\u3066CakePHP4 \u306e\u4ed5\u69d8\u306b\u8fd1\u3065\u3051\u307e\u3059\u3002\u4eca\u5f8c\u3001CakePHP4 \u7248\u3092\u30ea\u30ea\u30fc\u30b9\u3057\u3066\u3082 CakePHP2 \u7248 \u3092\u30d9\u30fc\u30b9\u3068\u3057\u305f\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092 CakePHP4 \u7248\u306b\u79fb\u884c\u3059\u308b\u307e\u3067\u306b\u306f\u76f8\u5f53\u306a\u671f\u9593\u304c\u5fc5\u8981\u3068\u4e88\u60f3\u3057\u3066\u3044\u307e\u3059\u3002\u305d\u306e\u305f\u3081\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u6027\u3082\u8003\u3048\u3066\u3001CakePHP2 \u7248\u306e\u30bd\u30fc\u30b9\u3068 CakePHP4 \u7248\u306e\u30bd\u30fc\u30b9\u306f\u3067\u304d\u308b\u9650\u308a\u5171\u901a\u5316\u3057\u305f\u3044\u3068\u3044\u3046\u601d\u60d1\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u6b21\u306b CakePHP2 \u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u69cb\u6210\u3084\u30d5\u30a1\u30a4\u30eb\u5f62\u5f0f\u3001\u6587\u5b57\u5217\u3084\u69cb\u6587\u3092\u3001 CakePHP4 \u306e\u4ed5\u69d8\u306b\u5408\u308f\u305b\u3066\u4e00\u62ec\u5909\u63db\u3092\u884c\u3046\u30b3\u30f3\u30d0\u30fc\u30bf\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002\u73fe\u5728\u3001\u79fb\u884c\u5bfe\u8c61\u306e\u30bd\u30d5\u30c8\u30a6\u30a7\u30a2\u304b\u3089\u30d5\u30a9\u30fc\u30af\u3057\u305f\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u304c\u3044\u304f\u3064\u3082\u5b58\u5728\u3057\u3066\u304a\u308a\u3001\u305d\u308c\u3089\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u79fb\u884c\u3082\u5186\u6ed1\u306b\u884c\u3044\u305f\u3044\u3068\u3044\u3046\u601d\u60d1\u304c\u3042\u308a\u307e\u3059\u3002\u305f\u3060\u3057\u30e2\u30c7\u30eb\u5468\u308a\u306e\u30bd\u30fc\u30b9\u306f\u69cb\u9020\u304c\u5927\u304d\u304f\u7570\u306a\u308b\u305f\u3081\u3001bake \u306b\u3066\u30b3\u30fc\u30c9\u3092\u518d\u4f5c\u6210\u3057\u3001\u500b\u5225\u306b\u79fb\u690d\u3059\u308b\u3053\u3068\u3068\u3057\u307e\u3059\u3002\u30b3\u30f3\u30d0\u30fc\u30bf\u306f\u3042\u304f\u307e\u3067\u306e\u624b\u4f5c\u696d\u3092\u6e1b\u3089\u3059\u305f\u3081\u306e\u3082\u306e\u3067\u3001\u5168\u3066\u306e\u30b3\u30fc\u30c9\u3092\u5909\u63db\u3059\u308b\u308f\u3051\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u5168\u4f53\u306e\u30b3\u30fc\u30c9\u306e6\u5272\u3092\u81ea\u52d5\u5909\u63db\u3059\u308b\u3053\u3068\u3092\u76ee\u6a19\u3068\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">CakePHP2 \u5074\u306e\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0<\/h3>\n\n\n\n<p>CakePHP4 \u3078\u79fb\u884c\u3059\u308b\u524d\u306b\u3001\u4e8b\u524d\u306b CakePHP2 \u5074\u3067\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0\u3092\u884c\u3044\u307e\u3059\u3002\u4e3b\u306a\u5185\u5bb9\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002<\/p>\n\n\n\n<ol id=\"block-c33dcba6-c53f-4c0f-8289-83923b849ad6\" class=\"wp-block-list\">\n<li>array() \u3092 [] \u5f62\u5f0f\u306b\u5909\u63db<\/li>\n\n\n\n<li>.ctp \u30d5\u30a1\u30a4\u30eb\u306e &lt;?php echo \u3092 &lt;?= \u5f62\u5f0f\u306b\u5909\u63db<\/li>\n\n\n\n<li>CakePHP \u6a19\u6e96\u30e1\u30bd\u30c3\u30c9\u306e\u30e9\u30c3\u30d4\u30f3\u30b0<\/li>\n\n\n\n<li>\u975e\u4e92\u63db\u30e1\u30bd\u30c3\u30c9\u306e\u7f6e\u304d\u63db\u3048<\/li>\n\n\n\n<li>\u305d\u306e\u4ed6\uff08SQL\u306e\u3079\u305f\u66f8\u304d\u7b49\uff09<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">1. array() \u3092 [] \u5f62\u5f0f\u306b\u5909\u63db<\/h3>\n\n\n\n<p>CakePHP2\u306e\u6642\u4ee3\u306f\u3001\u9577\u3089\u304f PHP5.3 \u3092\u30b5\u30dd\u30fc\u30c8\u3057\u3066\u3044\u305f\u3053\u3068\u3082\u3042\u308a\u3001\u914d\u5217\u306e\u8a18\u8ff0\u306b array() \u3092\u4f7f\u308f\u308c\u3066\u304d\u307e\u3057\u305f\u3002\u3057\u304b\u3057 PHP5.4 \u4ee5\u964d\u306f [] \uff08\u77ed\u7e2e\u69cb\u6587\uff09\u304c\u4f7f\u7528\u3067\u304d\u3001\u73fe\u5728\u306f [] \u5f62\u5f0f\u304c\u4e00\u822c\u7684\u306a\u305f\u3081\u3001\u4e8b\u524d\u306b array() \u3092 [] \u5f62\u5f0f\u306b\u5909\u63db\u3059\u308b\u3068\u3057\u307e\u3057\u305f\u3002\uff08\u79fb\u884c\u5bfe\u8c61\u306e\u30bd\u30d5\u30c8\u30a6\u30a7\u30a2\u3082\u65e2\u306bPHP5.4\u3092\u6700\u5c0f\u30d0\u30fc\u30b8\u30e7\u30f3\u3068\u3057\u3066\u3044\u308b\u305f\u3081\u5909\u63db\u3059\u308b\u3053\u3068\u306b\u554f\u984c\u306f\u3042\u308a\u307e\u305b\u3093\u3002\uff09<\/p>\n\n\n\n<p>array() \u5f62\u5f0f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$users = $this-&gt;User-&gt;find('all', array(\n    'conditions' =&gt; array('User.role' =&gt; 'user'),\n    'order' =&gt; array('User.created' =&gt; 'desc')\n));<\/code><\/pre>\n\n\n\n<p>[] \uff08\u77ed\u7e2e\u69cb\u6587\uff09\u5f62\u5f0f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$users = $this-&gt;User-&gt;find('all', &#91;\n    'conditions' =&gt; &#91;'User.role' =&gt; 'user'],\n    'order' =&gt; &#91;'User.created' =&gt; 'desc']\n]);<\/code><\/pre>\n\n\n\n<p>\u5909\u63db\u306f\u624b\u4f5c\u696d\u3067\u306f\u306a\u304f\u3001\u4ee5\u4e0b\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u7528\u3057\u3066\u4e00\u62ec\u5909\u63db\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>PHP 5.4 Short Array Syntax Converter<br><a href=\"https:\/\/github.com\/thomasbachem\/php-short-array-syntax-converter\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/thomasbachem\/php-short-array-syntax-converter<\/a><\/p>\n\n\n\n<p>\u30b3\u30de\u30f3\u30c9\u30d7\u30ed\u30f3\u30d7\u30c8\u3067\u4ee5\u4e0b\u306e\u3088\u3046\u306a convert.php \u3092\u5b9f\u884c\u3057\u307e\u3059\u3002(Windows \u306e\u5834\u5408)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>FOR \/f \"tokens=*\" %a in ('dir Config\\*.php \/S\/B') DO php convert.php %a -w\nFOR \/f \"tokens=*\" %a in ('dir Controller\\*.php \/S\/B') DO php convert.php %a -w\nFOR \/f \"tokens=*\" %a in ('dir Model\\*.php \/S\/B') DO php convert.php %a -w\nFOR \/f \"tokens=*\" %a in ('dir Vendor\\*.php \/S\/B') DO php convert.php %a -w\nFOR \/f \"tokens=*\" %a in ('dir View\\*.php \/S\/B') DO php convert.php %a -w\nFOR \/f \"tokens=*\" %a in ('dir View\\*.ctp \/S\/B') DO php convert.php %a -w\nFOR \/f \"tokens=*\" %a in ('dir webroot\\*.php \/S\/B') DO php convert.php %a -w<\/code><\/pre>\n\n\n\n<p>\u3053\u308c\u3067\u898b\u305f\u76ee\u3082\u304b\u306a\u308a\u3059\u3063\u304d\u308a\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. .ctp \u30d5\u30a1\u30a4\u30eb\u306e &lt;?php echo \u3092 &lt;?= \u5f62\u5f0f\u306b\u5909\u63db<\/h3>\n\n\n\n<p>CakePHP2\u3067\u306f\u3001View \u306e .ctp \u30d5\u30a1\u30a4\u30eb\u3067\u6587\u5b57\u5217\u3092\u51fa\u529b\u3059\u308b\u969b\u3001&lt;?php echo &#8220;xxx&#8221; ?&gt; \u304c\u4f7f\u308f\u308c\u3066\u304d\u307e\u3057\u305f\u3002\u73fe\u5728\u306f &lt;?= &#8220;xxx&#8221; ?&gt;\u3068\u7565\u3059\u308b\u306e\u304c\u4e00\u822c\u7684\u3068\u306a\u3063\u3066\u3044\u307e\u3059\u3002\u305d\u3053\u3067 gerp \u7f6e\u63db\u30c4\u30fc\u30eb\u306a\u3069\u3092\u4f7f\u3044\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b &lt;?php echo \u3092 &lt;?= \u5f62\u5f0f\u306b\u4e00\u62ec\u7f6e\u63db\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u7f6e\u63db\u524d<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;div class=\"panel panel-success\"&gt;\n  &lt;div class=\"panel-heading\"&gt;&lt;?php echo __('\u304a\u77e5\u3089\u305b\u4e00\u89a7'); ?&gt;&lt;\/div&gt;\n  &lt;div class=\"panel-body\"&gt;\n    &lt;table cellpadding=\"0\" cellspacing=\"0\"&gt;\n    &lt;thead&gt;\n    &lt;tr&gt;\n      &lt;th&gt;&lt;?php echo $this-&gt;Paginator-&gt;sort('created',   __('\u65e5\u4ed8')); ?&gt;&lt;\/th&gt;\n      &lt;th&gt;&lt;?php echo $this-&gt;Paginator-&gt;sort('title',   __('\u30bf\u30a4\u30c8\u30eb')); ?&gt;&lt;\/th&gt;\n    &lt;\/tr&gt;\n    &lt;\/thead&gt;\n    &lt;tbody&gt;\n    &lt;?php foreach ($infos as $info): ?&gt;\n    &lt;tr&gt;\n      &lt;td\"&gt;&lt;?php echo $info&#91;'Info']&#91;'created']; ?&gt;&lt;\/td&gt;\n      &lt;td&gt;&lt;?php echo $this-&gt;Html-&gt;link($info&#91;'Info']&#91;'title'], &#91;'action' =&gt; 'view', $info&#91;'Info']&#91;'id']]); ?&gt;&amp;nbsp;&lt;\/td&gt;\n    &lt;\/tr&gt;\n    &lt;?php endforeach; ?&gt;\n    &lt;\/tbody&gt;\n    &lt;\/table&gt;\n    &lt;?php echo $this-&gt;element('paging');?&gt;\n  &lt;\/div&gt;\n&lt;\/div&gt;<\/code><\/pre>\n\n\n\n<p>\u7f6e\u63db\u5f8c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;div class=\"panel panel-success\"&gt;\n  &lt;div class=\"panel-heading\"&gt;&lt;?= __('\u304a\u77e5\u3089\u305b\u4e00\u89a7'); ?&gt;&lt;\/div&gt;\n  &lt;div class=\"panel-body\"&gt;\n    &lt;table cellpadding=\"0\" cellspacing=\"0\"&gt;\n    &lt;thead&gt;\n    &lt;tr&gt;\n      &lt;th&gt;&lt;?= $this-&gt;Paginator-&gt;sort('created',   __('\u65e5\u4ed8')); ?&gt;&lt;\/th&gt;\n      &lt;th&gt;&lt;?= $this-&gt;Paginator-&gt;sort('title',   __('\u30bf\u30a4\u30c8\u30eb')); ?&gt;&lt;\/th&gt;\n    &lt;\/tr&gt;\n    &lt;\/thead&gt;\n    &lt;tbody&gt;\n    &lt;?php foreach ($infos as $info): ?&gt;\n    &lt;tr&gt;\n      &lt;td&gt;&lt;?= $info&#91;'Info']&#91;'created']; ?&gt;&lt;\/td&gt;\n      &lt;td&gt;&lt;?= $this-&gt;Html-&gt;link($info&#91;'Info']&#91;'title'], &#91;'action' =&gt; 'view', $info&#91;'Info']&#91;'id']]); ?&gt;&amp;nbsp;&lt;\/td&gt;\n    &lt;\/tr&gt;\n    &lt;?php endforeach; ?&gt;\n    &lt;\/tbody&gt;\n    &lt;\/table&gt;\n    &lt;?= $this-&gt;element('paging');?&gt;\n  &lt;\/div&gt;\n&lt;\/div&gt;\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3. CakePHP \u6a19\u6e96\u30e1\u30bd\u30c3\u30c9\u3001\u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u30e9\u30c3\u30d4\u30f3\u30b0<\/h3>\n\n\n\n<p>CakePHP2 \u3068 CakePHP4 \u3067\u306f\u30bb\u30c3\u30b7\u30e7\u30f3\u3084\u30ea\u30af\u30a8\u30b9\u30c8\u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u30a2\u30af\u30bb\u30b9\u7528\u306e\u30af\u30e9\u30b9\u69cb\u6210\u304c\u7570\u306a\u308a\u307e\u3059\u3002\u305d\u3053\u3067 CakePHP \u306e\u30e1\u30bd\u30c3\u30c9\u3001\u30d7\u30ed\u30d1\u30c6\u30a3\u306b\u76f4\u63a5\u30a2\u30af\u30bb\u30b9\u3059\u308b\u306e\u3067\u306f\u306a\u304f\u3001\u30e9\u30c3\u30d4\u30f3\u30b0\u3059\u308b\u3053\u3068\u3068\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>CakePHP2 \u3068 CakePHP4 \u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8a18\u8ff0\u65b9\u6cd5\u304c\u7570\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ CakePHP2 \u30bb\u30c3\u30b7\u30e7\u30f3\u306e\u53c2\u7167\u3001\u66f8\u304d\u8fbc\u307f\u3001\u524a\u9664\n$this-&gt;Session-&gt;read($key);\n$this-&gt;Session-&gt;write($key, $value);\n$this-&gt;Session-&gt;delete($key);\n\n\/\/ CakePHP4 \u30bb\u30c3\u30b7\u30e7\u30f3\u306e\u53c2\u7167\u3001\u66f8\u304d\u8fbc\u307f\u3001\u524a\u9664\n$this-&gt;getRequest()-&gt;getSession()-&gt;read($key);\n$this-&gt;getRequest()-&gt;getSession()-&gt;write($key, $value);\n$this-&gt;getRequest()-&gt;getSession()-&gt;delete($key);\n\n\/\/ CakePHP2 \u30ed\u30b0\u30a4\u30f3\u30e6\u30fc\u30b6\u60c5\u5831\u306e\u53d6\u5f97\n$this-&gt;Auth-&gt;user($key);\n\/\/ CakePHP4 \u30ed\u30b0\u30a4\u30f3\u30e6\u30fc\u30b6\u60c5\u5831\u306e\u53d6\u5f97\n$this-&gt;getRequest()-&gt;getAttribute('identity')-&gt;get($key);\n\n\/\/ CakePHP2 \u30af\u30a8\u30ea\u30b9\u30c8\u30ea\u30f3\u30b0\u306e\u53d6\u5f97\n$this-&gt;request-&gt;query&#91;$key]);\n\/\/ CakePHP4 \u30af\u30a8\u30ea\u30b9\u30c8\u30ea\u30f3\u30b0\u306e\u53d6\u5f97\n$this-&gt;getRequest()-&gt;getQuery($key);\n\n\/\/ CakePHP2 POST\u30c7\u30fc\u30bf\u306e\u53d6\u5f97\n$this-&gt;Auth-&gt;user($key);\n\/\/ CakePHP4 POST\u30c7\u30fc\u30bf\u306e\u53d6\u5f97\n$this-&gt;getRequest()-&gt;getData();\n<\/code><\/pre>\n\n\n\n<p>\u3053\u306e\u3088\u3046\u306a\u30b3\u30fc\u30c9\u3092\u6bce\u56de\u30bd\u30fc\u30b9\u30d5\u30a1\u30a4\u30eb\u3054\u3068\u306b\u66f8\u304d\u63db\u3048\u308b\u306e\u306f\u3068\u3066\u3082\u624b\u9593\u304c\u304b\u304b\u308a\u3001\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u6027\u3082\u3088\u304f\u3042\u308a\u307e\u305b\u3093\u3002\u305d\u3053\u3067 CakePHP \u7279\u6709\u306e\u30e1\u30bd\u30c3\u30c9\u3001\u30d7\u30ed\u30d1\u30c6\u30a3\u306f\u3067\u304d\u308b\u9650\u308a\u30e9\u30c3\u30d4\u30f3\u30b0\u3059\u308b\u3053\u3068\u3068\u3057\u307e\u3057\u305f\u3002\u3053\u3046\u3059\u308b\u3053\u3068\u306b\u3088\u3063\u3066 CakePHP4 \u3078\u79fb\u884c\u5f8c\u3082\u5927\u534a\u306e\u30b3\u30fc\u30c9\u306f\u66f8\u304d\u63db\u3048\u306a\u304f\u3066\u3059\u3080\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>CakePHP2 \u306e AppController.php \u3067\u3053\u306e\u3088\u3046\u306b\u30e9\u30c3\u30d4\u30f3\u30b0\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>protected function readSession($key)\n{\n    return $this-&gt;Session-&gt;read($key);\n}\n\nprotected function deleteSession($key)\n{\n    $this-&gt;Session-&gt;delete($key);\n}\n\nprotected function writeSession($key)\n{\n    $this-&gt;Session-&gt;write($key, $value);\n}\n\nprotected function readAuthUser($key)\n{\n    return $this-&gt;Auth-&gt;user($key);\n}\n\nprotected function getQuery($key)\n{\n    return $this-&gt;request-&gt;query&#91;$key];\n}\n\nprotected function getData($key = null)\n{\n    return $this-&gt;request-&gt;data&#91;$key];\n}<\/code><\/pre>\n\n\n\n<p>CakePHP4 \u5074\u306e AppController.php \u3067\u306f\u3053\u306e\u3088\u3046\u306b\u30e9\u30c3\u30d4\u30f3\u30b0\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>protected function readSession($key)\n{\n    return $this-&gt;getRequest()-&gt;getSession()-&gt;read($key);\n}\n\nprotected function deleteSession($key)\n{\n    $this-&gt;getRequest()-&gt;getSession()-&gt;delete($key);\n}\n\nprotected function writeSession($key, $value)\n{\n    $this-&gt;getRequest()-&gt;getSession()-&gt;write($key, $value);\n}\n\nprotected function readAuthUser($key)\n{\n    return $this-&gt;getRequest()-&gt;getAttribute('identity')-&gt;get($key);\n}\n\nprotected function getQuery($key)\n{\n    return $this-&gt;getRequest()-&gt;getQuery($key);\n}\n\nprotected function getData($key)\n{\n    return $this-&gt;getRequest()-&gt;getData($key);\n}\n<\/code><\/pre>\n\n\n\n<p>\u3053\u308c\u3067\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u304b\u3089\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3001CakePHP2 \u3068 CakePHP4 \u3067\u540c\u3058\u30b3\u30fc\u30c9\u3067\u30e1\u30bd\u30c3\u30c9\u306b\u30a2\u30af\u30bb\u30b9\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$this-&gt;readSession($key);\n$this-&gt;deleteSession($key);\n$this-&gt;writeSession($key, $value);\n$this-&gt;readAuthUser($key);\n$this-&gt;getQuery($key);\n$this-&gt;getData($key);<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">4. \u975e\u4e92\u63db\u30e1\u30bd\u30c3\u30c9\u306e\u7f6e\u304d\u63db\u3048<\/h3>\n\n\n\n<p>CakePHP4 \u3067\u306f\u591a\u304f\u306e\u30e1\u30bd\u30c3\u30c9\u306e\u4ed5\u69d8\u304c\u5909\u66f4\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u4f8b\u3048\u3070\u30e2\u30c7\u30eb\u304b\u3089\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u969b\u3001CakePHP2 \u3067\u306f\u3053\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3057\u3066\u3044\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$user = $this-&gt;User-&gt;find('first', &#91;\n    'conditions' =&gt; &#91;'User.id' =&gt; $user_id]\n]);\n\n$users = $this-&gt;User-&gt;find('all', &#91;\n    'conditions' =&gt; &#91;'User.role' =&gt; 'admin'],\n    'order' =&gt; &#91;'User.created' =&gt; 'desc']\n]);<\/code><\/pre>\n\n\n\n<p>CakePHP4 \u3067\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3059\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002\u7279\u306b\u30e1\u30bd\u30c3\u30c9\u30c1\u30a7\u30fc\u30f3\u3092\u4f7f\u7528\u3057\u3066\u30af\u30a8\u30ea\u306e\u6761\u4ef6\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u304c\u7279\u5fb4\u3068\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$user = $this-&gt;User-&gt;get($user_id);\n\n$users = $this-&gt;User-&gt;find()\n    -&gt;where(&#91;'role' =&gt; 'user'])\n    -&gt;order(&#91;'User.created' =&gt; 'desc'])\n    -&gt;all();<\/code><\/pre>\n\n\n\n<p>\u3053\u308c\u3092 CakePHP2 \u3067\u3082\u540c\u69d8\u306b\u8a18\u8ff0\u3067\u304d\u308b\u3088\u3046\u306b\u3001app\\Model\\AppModel.php \u306b\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30b3\u30fc\u30c9\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class AppModel extends Model\n{\n    private $options = &#91;];\n    \n    public function get($id)\n    {\n        return $this-&gt;findById($id);\n    }\n\n    public function find($type = null, $options = &#91;])\n    {\n        if($type == null) {\n            $this-&gt;options = &#91;];\n            return $this;\n        }\n        \n        return parent::find($type, $options);\n    }\n\n    public function select($value)\n    {\n        $this-&gt;options&#91;'fields'] = $value;\n        return $this;\n    }\n\n    public function where($value)\n    {\n        $this-&gt;options&#91;'conditions'] = $value;\n        return $this;\n    }\n\n    public function order($value)\n    {\n        $this-&gt;options&#91;'order'] = $value;\n        return $this;\n    }\n\n    public function limit($value)\n    {\n        $this-&gt;options&#91;'limit'] = $value;\n        return $this;\n    }\n\n    public function page($value)\n    {\n        $this-&gt;options&#91;'page'] = $value;\n        return $this;\n    }\n\n    public function all()\n    {\n        return parent::find('all', $this-&gt;options);\n    }\n\n    public function first()\n    {\n        return parent::find('first', $this-&gt;options);\n    }\n\n    public function count()\n    {\n        return parent::find('count', $this-&gt;options);\n    }\n}\n<\/code><\/pre>\n\n\n\n<p>\u3053\u308c\u3067 CakePHP2 \u3068 CakePHP4 \u3067\u540c\u3058\u30b3\u30fc\u30c9\u304c\u52d5\u4f5c\u3059\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u307e\u305f\u5b9f\u9a13\u7684\u306a\u5b9f\u88c5\u3067\u3059\u304c\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5909\u66f4\u3059\u308b\u3053\u3068\u3088\u3063\u3066\u3001all() \u3084 first() \u306e\u7d50\u679c\u3092\u9023\u60f3\u914d\u5217\u3067\u306f\u306a\u304f\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u5909\u63db\u3059\u308b\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class AppModel extends Model\n{\n    private $options = &#91;];\n    private $is_object = false; \/\/ \u9023\u60f3\u914d\u5217\u3092\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u5909\u63db\u3059\u308b\u304b\u3069\u3046\u304b\uff08\u5b9f\u9a13\u7684\u5b9f\u88c5\uff09\n    \n    public function get($id)\n    {\n        return $this-&gt;findById($id);\n    }\n\n    public function find($type = null, $options = &#91;])\n    {\n        if($type == null)\n        {\n            $this-&gt;options = &#91;];\n            return $this;\n        }\n        \n        return parent::find($type, $options);\n    }\n\n    public function select($value)\n    {\n        $this-&gt;options&#91;'fields'] = $value;\n        return $this;\n    }\n\n    public function where($value)\n    {\n        $this-&gt;options&#91;'conditions'] = $value;\n        return $this;\n    }\n\n    public function order($value)\n    {\n        $this-&gt;options&#91;'order'] = $value;\n        return $this;\n    }\n\n    public function limit($value)\n    {\n        $this-&gt;options&#91;'limit'] = $value;\n        return $this;\n    }\n\n    public function page($value)\n    {\n        $this-&gt;options&#91;'page'] = $value;\n        return $this;\n    }\n\n    public function all()\n    {\n        if($this-&gt;is_object) {\n            $data = parent::find('all', $this-&gt;options);\n            \n            \/\/ \u9023\u60f3\u914d\u5217&#91;Model]&#91;field] \u3092 &#91;field] \u306b\u5909\u66f4\n            foreach($data as &amp;$row) {\n                $row = array_merge($row, $row&#91;$this-&gt;name]);\n                unset($row&#91;$this-&gt;name]);\n            }\n            \n            \/\/ &#91;Model]&#91;field] \u3092 \u524a\u9664\n            $object= new stdClass();\n            $data = $this-&gt;_array_to_object($data, $object);\n            \n            return $data;\n        }\n        return parent::find('all', $this-&gt;options);\n    }\n\n    public function first()\n    {\n        if($this-&gt;is_object) {\n            $data = parent::find('first', $this-&gt;options);\n            \n            \/\/ \u9023\u60f3\u914d\u5217&#91;Model]&#91;field] \u3092 &#91;field] \u306b\u5909\u66f4\n            $data = array_merge($data, $data&#91;$this-&gt;name]);\n            \n            \/\/ &#91;Model]&#91;field] \u3092 \u524a\u9664\n            unset($data&#91;$this-&gt;name]);\n            \n            $object= new stdClass();\n            $data = $this-&gt;_array_to_object($data, $object);\n            \n            return $data;\n        }\n        return parent::find('first', $this-&gt;options);\n    }\n\n    public function count()\n    {\n        return parent::find('count', $this-&gt;options);\n    }\n\n    \/**\n     * \u53d6\u5f97\u5f62\u5f0f\u3092\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3068\u8a2d\u5b9a\n     *\/\n    public function convert()\n    {\n        $this-&gt;is_object = true;\n        return $this;\n    }\n    \n    \/**\n     * \u914d\u5217\u3092\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u5909\u63db\n     *\/\n    private function _array_to_object($array, &amp;$obj)\n    {\n        foreach($array as $key =&gt; $value) {\n            if(is_array($value)) {\n                \/\/ \u30c7\u30fc\u30bf\u304c\u8907\u6570\u304b\u3064\u9023\u60f3\u914d\u5217\u306e\u5834\u5408\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u540d\u306e\u6700\u5f8c\u306b s\u3092\u3064\u3051\u308b\n                if(is_string($key))\n                    $key .= 's';\n                \n                $obj-&gt;{strtolower($key)} = new stdClass();\n                $this-&gt;_array_to_object($value, $obj-&gt;{strtolower($key)});\n            } else {\n                $obj-&gt;{strtolower($key)} = $value;\n            }\n        }\n        return $obj;\n    }\n}<\/code><\/pre>\n\n\n\n<p>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3078\u306e\u5909\u63db\u65b9\u6cd5<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$course = $this-&gt;Course-&gt;find()\n     -&gt;where(['Course.id' =&gt; $course_id])\n     -&gt;convert() \/\/ \u53d6\u5f97\u7d50\u679c\u3092\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3068\u6307\u5b9a\n     -&gt;first();<\/pre>\n\n\n\n<p>\u51fa\u529b\u7d50\u679c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>object(stdClass) {\n    contents =&gt; object(stdClass) {\n        0 =&gt; object(stdClass) {\n            id =&gt; '463'\n            title =&gt; 'test20210113'\n            created =&gt; '2020-12-23 18:36:56'\n        }\n        1 =&gt; object(stdClass) {\n            id =&gt; '465'\n            title =&gt; 'pdf'\n            created =&gt; '2021-01-12 18:27:20'\n            modified =&gt; '2021-01-13 12:08:27'\n        }\n    }\n    id =&gt; '98'\n    title =&gt; '\u30b3\u30fc\u30b9\u306e\u30bf\u30a4\u30c8\u30eb'\n    created =&gt; '2016-01-22 07:00:55'\n    modified =&gt; '2018-02-07 18:57:16'\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">5. \u305d\u306e\u4ed6<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">5-1. SQL\u306e\u3079\u305f\u66f8\u304d<\/h4>\n\n\n\n<p>O\/R\u30de\u30c3\u30d4\u30f3\u30b0\u306f\u3068\u3066\u3082\u4fbf\u5229\u3067\u5927\u534a\u306e\u5834\u5408\u306b\u306f\u30e1\u30ea\u30c3\u30c8\u306e\u307b\u3046\u304c\u5927\u304d\u3044\u306e\u3067\u3059\u304c\u3001\u5c11\u3057\u8907\u96d1\u306a\u96c6\u8a08\u3092\u884c\u304a\u3046\u3068\u3059\u308b\u3068\u3001\u3068\u305f\u3093\u306b\u5b66\u7fd2\u30b3\u30b9\u30c8\u304c\u9ad8\u304f\u306a\u308b\u50be\u5411\u304c\u3042\u308a\u307e\u3059\u3002\u307e\u305f\u8907\u96d1\u306a\u30af\u30a8\u30ea\u307b\u3069\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3092\u30a2\u30c3\u30d7\u30b0\u30ec\u30fc\u30c9\u3059\u308b\u969b\u3001\u969c\u5bb3\u306b\u306a\u308b\u3053\u3068\u304c\u591a\u3005\u3042\u308a\u307e\u3059\u3002\u305d\u3053\u3067\u8907\u96d1\u306a\u30c7\u30fc\u30bf\u306e\u96c6\u8a08\u3092\u884c\u3046\u5834\u5408\u306f\u3001SQL \u306e\u3079\u305f\u66f8\u304d\u3092\u57fa\u672c\u3068\u3059\u308b\u3053\u3068\u3057\u307e\u3057\u305f\u3002SQL \u306f\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306b\u4f9d\u5b58\u3057\u306a\u3044\u305f\u3081\u3001\u79fb\u884c\u306b\u3082\u9069\u3057\u3066\u3044\u308b\u3068\u8a00\u3048\u307e\u3059\u3002\u5fc5\u8981\u306b\u5fdc\u3058\u3066\u30d3\u30e5\u30fc\u3084\u30b9\u30c8\u30a2\u30c9\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u306a\u3069\u3082\u6d3b\u7528\u3057\u307e\u3059\u3002\u3053\u306e\u3088\u3046\u306a\u5bfe\u5fdc\u3092\u884c\u3046\u306e\u306f\u3001\u79fb\u884c\u5bfe\u8c61\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u304c MySQL \u306e\u307f\u3092\u30b5\u30dd\u30fc\u30c8\u3057\u3066\u3044\u308b\u305f\u3081\u3001\u307b\u304b\u306eDB\u3092\u8003\u616e\u3059\u308b\u3053\u3068\u304c\u306a\u3044\u3053\u3068\u3082\u7406\u7531\u306e\u4e00\u3064\u3068\u8a00\u3048\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u8907\u96d1\u306a\u30af\u30a8\u30ea\u306e\u4f8b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public function getCourseRecord($user_id)\n{\n  $sql = &lt;&lt;&lt;EOF\nSELECT Course.*, Course.id, Course.title, first_date, last_date,\n   (ifnull(content_cnt, 0) - ifnull(study_cnt, 0) ) as left_cnt\nFROM ib_courses Course\nLEFT OUTER JOIN\n   (SELECT h.course_id, h.user_id,\n           MAX(DATE_FORMAT(created, '%Y\/%m\/%d')) as last_date,\n           MIN(DATE_FORMAT(created, '%Y\/%m\/%d')) as first_date\n      FROM ib_records h\n     WHERE h.user_id =:user_id\n     GROUP BY h.course_id, h.user_id) Record\n ON Record.course_id   = Course.id\nAND Record.user_id     =:user_id\nLEFT OUTER JOIN\n    (SELECT course_id, COUNT(*) as study_cnt\n       FROM\n        (SELECT r.course_id, r.content_id, COUNT(*)\n           FROM ib_records r\n          INNER JOIN ib_contents c ON r.content_id = c.id AND r.course_id = c.course_id\n          WHERE r.user_id = :user_id\n            AND status = 1\n          GROUP BY r.course_id, r.content_id) as c\n     GROUP BY course_id) StudyCount\n ON StudyCount.course_id   = Course.id\nLEFT OUTER JOIN\n    (SELECT course_id, COUNT(*) as content_cnt\n       FROM ib_contents\n      WHERE kind NOT IN ('label', 'file')\n        AND status = 1\n      GROUP BY course_id) ContentCount\n ON ContentCount.course_id   = Course.id\nWHERE id IN (SELECT course_id FROM ib_users_groups ug INNER JOIN ib_groups_courses gc ON ug.group_id = gc.group_id WHERE user_id = :user_id)\n OR id IN (SELECT course_id FROM ib_users_courses WHERE user_id = :user_id)\nORDER BY Course.sort_no asc\nEOF;\n\n$params = &#91;\n    'user_id' =&gt; $user_id\n];\n\n  $data = $this-&gt;query($sql, $params);\n  return $data;\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">5-2. \u524a\u9664\u3055\u308c\u305f\u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u8ffd\u52a0<\/h4>\n\n\n\n<p>CakePHP4 \u3067\u306f CakePHP2 \u3067\u3088\u304f\u4f7f\u7528\u3057\u3066\u3044\u305f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30d7\u30ed\u30d1\u30c6\u30a3\u304c\u524a\u9664\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$this-&gt;action;\n$this-&gt;webroot;<\/code><\/pre>\n\n\n\n<p>\u524d\u8ff0\u306e\u3088\u3046\u306b\u30e9\u30c3\u30d4\u30f3\u30b0\u3059\u308b\u3053\u3068\u3082\u8003\u3048\u307e\u3057\u305f\u304c\u3001\u3042\u307e\u308a\u306b\u3082\u4fee\u6b63\u7b87\u6240\u304c\u591a\u304f\u306a\u308b\u305f\u3081\u3001CakePHP4 \u5074\u306e\u4ee5\u4e0b\u306e2\u30d5\u30a1\u30a4\u30eb\u306b\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u8ffd\u52a0\u3059\u308b\u3053\u3068\u3068\u3044\u305f\u3057\u307e\u3057\u305f\u3002\u3053\u308c\u3067 CakePHP2 \u3068\u540c\u3058\u30b3\u30fc\u30c9\u304c\u52d5\u4f5c\u3059\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>src\\Controller\\AppController.php<br>src\\View\\AppView.php<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public $action; \/\/CakePHP2\u306e\u4ed5\u69d8\u306e\u5f15\u7d99\u304e\npublic $webroot; \/\/CakePHP2\u306e\u4ed5\u69d8\u306e\u5f15\u7d99\u304e\n\npublic function initialize(): void\n{\n    parent::initialize();\n    $this-&gt;action = $this-&gt;request-&gt;getParam('action');\n    $this-&gt;webroot = Router::url('\/', true);\n}<\/code><\/pre>\n\n\n\n<p>\u6b21\u56de\u306f CakePHP2 \u304b\u3089 CakePHP4 \u3078\u306e\u30b3\u30f3\u30d0\u30fc\u30bf\u306e\u4f5c\u6210\u3068\u8a8d\u8a3c\u5468\u308a\u306e\u79fb\u884c\u306b\u3064\u3044\u3066\u66f8\u304f\u4e88\u5b9a\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306e\u30a2\u30c3\u30d7\u30b0\u30ec\u30fc\u30c9\u306f\u3001\u3057\u3070\u3057\u3070\u958b\u767a\u8005\u306b\u3068\u3063\u3066\u982d\u306e\u75db\u3044\u554f\u984c\u3068\u306a\u3063\u3066\u3044\u307e\u3059\u3002\u4eca\u56de\u306f\u6050\u3089\u304f\u591a\u304f\u306e\u7d44\u7e54\u3067\u8ab2\u984c\u3068\u306a\u3063\u3066\u3044\u308b\u3068\u601d\u308f\u308c\u308b CakePHP2 \u304b\u3089 CakePHP4 \u3078\u79fb\u884c\u306b\u3064\u3044\u3066\u53d6\u308a\u4e0a\u3052\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1363,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20,19],"tags":[],"class_list":["post-1290","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cakephp","category-oss"],"_links":{"self":[{"href":"https:\/\/tech.at-iroha.jp\/index.php?rest_route=\/wp\/v2\/posts\/1290","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tech.at-iroha.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tech.at-iroha.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tech.at-iroha.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tech.at-iroha.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1290"}],"version-history":[{"count":94,"href":"https:\/\/tech.at-iroha.jp\/index.php?rest_route=\/wp\/v2\/posts\/1290\/revisions"}],"predecessor-version":[{"id":1762,"href":"https:\/\/tech.at-iroha.jp\/index.php?rest_route=\/wp\/v2\/posts\/1290\/revisions\/1762"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/tech.at-iroha.jp\/index.php?rest_route=\/wp\/v2\/media\/1363"}],"wp:attachment":[{"href":"https:\/\/tech.at-iroha.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1290"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tech.at-iroha.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1290"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tech.at-iroha.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1290"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}