{"id":4786,"date":"2013-04-30T16:56:27","date_gmt":"2013-04-30T07:56:27","guid":{"rendered":"http:\/\/www.moonmile.net\/blog\/?p=4786"},"modified":"2013-04-30T16:57:22","modified_gmt":"2013-04-30T07:57:22","slug":"cakephp-%e3%83%88%e3%83%a9%e3%83%b3%e3%82%b6%e3%82%af%e3%82%b7%e3%83%a7%e3%83%b3%e3%82%92%e5%88%a9%e7%94%a8%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"http:\/\/www.moonmile.net\/blog\/archives\/4786","title":{"rendered":"[CakePHP] \u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u3092\u5229\u7528\u3059\u308b"},"content":{"rendered":"<p>\n\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u3092\u5229\u7528\u3059\u308b&#8230;\u304c\u3001WEB\u7cfb\u306e\u5834\u5408\u306f\u3001\u30ef\u30f3\u30b3\u30fc\u30eb\u306e\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u3057\u304b\u4f7f\u3048\u306a\u3044\u306e\u3067\u3001\u8907\u6570\u306e\u30b3\u30fc\u30eb\/Web API\u306b\u307e\u305f\u304c\u308b\u5834\u5408\u306f\u3001\uff12\u30d5\u30a7\u30fc\u30ba\u30b3\u30df\u30c3\u30c8\u306e\u65b9\u6cd5\u3092\u53d6\u308b\u3002\u307e\u3042\u3001\u30c1\u30b1\u30c3\u30c8\u4e88\u7d04\u3068\u304b\u306e\u3088\u3046\u306b\u666e\u901a\u306f\u30c0\u30fc\u30c6\u30a3\u30b3\u30df\u30c3\u30c8\u306e\u65b9\u5f0f\u304c\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u3088\u3044\u3002\u6700\u5f8c\u306b\u30c1\u30a7\u30c3\u30af\u3092\u5165\u308c\u3066\u3001\u6574\u5408\u6027\u304c\u306a\u3051\u308c\u3070\/\u65e2\u306b\u4e88\u7d04\u6e08\u307f\u3060\u3068\u304b\u306e\u5834\u5408\u306f\u3001\u30a8\u30e9\u30fc\u306b\u3057\u3066\u3057\u307e\u3046\u65b9\u5f0f\u3002\u793e\u5185\u696d\u52d9\u306e\u5834\u5408\u306f\u3001\u305d\u308c\u307b\u3069\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u5fc5\u8981\u3068\u3057\u306a\u3044 or \u9014\u4e2d\u306e\u5165\u529b\u3092\u7834\u68c4\u3055\u308c\u308b\u307b\u3046\u304c\u75db\u3044\u5834\u5408\u306f\u3001\u4e00\u6642\u5165\u529b\u3092\u4fdd\u6301\u3059\u308b\u65b9\u5f0f\u3067\u30bb\u30c3\u30b7\u30e7\u30f3\u3092\u4f5c\u308b\u3002\n<\/p>\n<p>\n\u3053\u3053\u306f\u30ef\u30f3\u30b3\u30fc\u30eb\u306e\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u3067\u3002\n<\/p>\n<p>\n\u25a0Model\n<\/p>\n<p>\nModel\/AppModel.php \u3092\u66f8\u304d\u63db\u3048\n<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\nclass AppModel extends Model {\n\tvar $db ;\n\tfunction begin()\n\t{\n\t    $db = ConnectionManager::getDataSource($this-&gt;useDbConfig);\n\t    $db-&gt;begin($this);\n\t}\n\t   \n\tfunction commit()\n\t{\n\t    $db = ConnectionManager::getDataSource($this-&gt;useDbConfig);\n\t    $db-&gt;commit($this);\n\t}\n\t   \n\tfunction rollback()\n\t{\n\t    $db = ConnectionManager::getDataSource($this-&gt;useDbConfig);\n\t    $db-&gt;rollback($this);\n\t}\n}\n<\/pre>\n<p>\n\u30b3\u30cd\u30af\u30b7\u30e7\u30f3\u304c Model \u306b\u4ed8\u5c5e\u3059\u308b\u306e\u3067\u3001$this-&gt;useDbConfig \u3082 Model \u5358\u4f4d\u306b\u306a\u3063\u3066\u3057\u307e\u3046\u3068\u3044\u3046\u7f60\u304c\u3042\u308b\u306e\u3067\u3001\u591a\u4eba\u6570\u3067\u4f7f\u3046\u5834\u5408\u306b\u306f\u8003\u616e\u304c\u5fc5\u8981\u3002\u305f\u3060\u3001\u5927\u62b5\u306e\u5834\u5408\u306f\u30ef\u30f3\u30b3\u30cd\u30af\u30b7\u30e7\u30f3\u3067\u6e08\u307e\u305b\u3066\u3057\u307e\u3046\u306e\u3067\u3001\u308f\u3056\u308f\u3056\u30de\u30eb\u30c1\u30b3\u30cd\u30af\u30b7\u30e7\u30f3\u3092\u5229\u7528\u3057\u3066\u306a\u3044\u5834\u5408\u306b\u306f\u7279\u306b\u554f\u984c\u306b\u306a\u3089\u306a\u3044\u3002\n<\/p>\n<p>\nCakePHP\u3067\u8907\u6570\u30c6\u30fc\u30d6\u30eb\u306b\u5bfe\u3059\u308b\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u3092\u4f7f\u3046\u5834\u5408 &#8211; takami_hiroki\u306e\u65e5\u8a18<br \/>\n<a href=\"http:\/\/d.hatena.ne.jp\/takami_hiroki\/20101109\/p1\">http:\/\/d.hatena.ne.jp\/takami_hiroki\/20101109\/p1<\/a>\n<\/p>\n<p>\n\u306e\u3088\u3046\u306b ADO.NET \u98a8\u306b Transaciton \u30af\u30e9\u30b9\u3092\u5225\u306b\u7528\u610f\u3057\u305f\u307b\u3046\u304c\u3088\u3044\u304b\u3082\u3002\n<\/p>\n<p>\n\u25a0Controller\n<\/p>\n<p>\n\u305f\u3081\u3057\u306b\u3001delete \u3067 commit\/rollback \u3057\u3066\u307f\u308b\u3002\n<\/p>\n<p>\nin Controller\/TestController.php\n<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\n\tpublic function delete($id=null) {\n\t\tif (isset($this-&gt;params&#x5B;&#039;url&#039;]&#x5B;&#039;id&#039;])) $id = $this-&gt;params&#x5B;&#039;url&#039;]&#x5B;&#039;id&#039;];\n\t\tif ( $id != null ) {\n\n\t\t\t\/\/ \u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u958b\u59cb\n\t\t    $this-&gt;Test-&gt;begin();\n    \t\t\/\/ \u51e6\u7406\u3092\u66f8\u304f\n\t\t\t\/\/ $this-&gt;Test-&gt;read(null, $id);\n\t\t\t$this-&gt;Test-&gt;delete( $id );\n\t\t\t\n\t\t\t\/\/ \u30b3\u30df\u30c3\u30c8 or \u30ed\u30fc\u30eb\u30d0\u30c3\u30af\n    \t\t$this-&gt;Test-&gt;rollback();\n    \t\t\/\/ $this-&gt;Test-&gt;commit();\n   \t\t}\n\t\t$this-&gt;set(&#039;Test&#039;,$this-&gt;Test-&gt;find(&#039;all&#039;));\n\t}\n<\/pre>\n<p>\n\u30b3\u30cd\u30af\u30b7\u30e7\u30f3\u304c $this-&gt;Test \u306b\u5c5e\u3057\u3066\u3044\u308b\u306e\u3060\u304c\u3001$this-&gt;Store \u3067\u3082\u540c\u3058\u3002ConnectionManager::getDataSource($this-&gt;useDbConfig); \u306a\u306e\u3067\u3002\n<\/p>\n<p>\n\u25a0View\n<\/p>\n<p>\nView \u306f\u540c\u3058\n<\/p>\n<p>\n\u25a0\u7d50\u679c\n<\/p>\n<p>\n\u524a\u9664\u306f\u30ed\u30fc\u30eb\u30d0\u30c3\u30af\u3055\u308c\u3066\u3001\u66f4\u65b0\u3055\u308c\u306a\u3044\u3002\n<\/p>\n<p><a href='http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2013\/04\/wpid-dworkblogimage20130430_08org.jpg'><img border='0' src='http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2013\/04\/wpid-dworkblogimage20130430_08thum.jpg'\/><\/a><\/p>\n<p>\n\u203b\u30af\u30a8\u30ea\u3092\u898b\u308b\u3068\u3001\u300cBEGIN\u300d\u3057\u304b\u306a\u3044\u3051\u3069\u5927\u4e08\u592b\u306a\u306e\u304b\uff1f\u52d5\u4f5c\u7684\u306b\u306f\u554f\u984c\u306a\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u3092\u5229\u7528\u3059\u308b&#8230;\u304c\u3001WEB\u7cfb\u306e\u5834\u5408\u306f\u3001\u30ef\u30f3\u30b3\u30fc\u30eb\u306e\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u3057\u304b\u4f7f\u3048\u306a\u3044\u306e\u3067\u3001\u8907\u6570\u306e\u30b3\u30fc\u30eb\/Web API\u306b\u307e\u305f\u304c\u308b\u5834\u5408\u306f\u3001\uff12\u30d5\u30a7\u30fc\u30ba\u30b3\u30df\u30c3\u30c8\u306e\u65b9\u6cd5\u3092\u53d6\u308b\u3002\u307e\u3042\u3001\u30c1\u30b1\u30c3\u30c8\u4e88\u7d04\u3068\u304b\u306e\u3088\u3046\u306b\u666e\u901a &hellip; <a href=\"http:\/\/www.moonmile.net\/blog\/archives\/4786\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[20],"tags":[],"class_list":["post-4786","post","type-post","status-publish","format-standard","hentry","category-cakephp"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/4786","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/comments?post=4786"}],"version-history":[{"count":1,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/4786\/revisions"}],"predecessor-version":[{"id":4787,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/4786\/revisions\/4787"}],"wp:attachment":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/media?parent=4786"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/categories?post=4786"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/tags?post=4786"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}