{"id":4762,"date":"2013-04-30T15:14:13","date_gmt":"2013-04-29T21:14:13","guid":{"rendered":"http:\/\/www.moonmile.net\/blog\/?p=4762"},"modified":"2013-04-30T15:14:54","modified_gmt":"2013-04-30T06:14:54","slug":"cakephp-%e6%8c%87%e5%ae%9a%e3%81%97%e3%81%9fid%e3%81%ae%e8%a1%8c%e3%81%a0%e3%81%91%e8%a1%a8%e7%a4%ba%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"http:\/\/www.moonmile.net\/blog\/archives\/4762","title":{"rendered":"[CakePHP] \u6307\u5b9a\u3057\u305fID\u306e\u884c\u3060\u3051\u8868\u793a\u3059\u308b"},"content":{"rendered":"<p>\nfindById \u3068\u304b findAllById \u3092\u4f7f\u3063\u3066 PK \u306e id \u3092\u4f7f\u3063\u3066\u53d6\u5f97\u3059\u308b\u30d1\u30bf\u30fc\u30f3\n<\/p>\n<p>\n\u25a0Model\n<\/p>\n<p>\nfind \u7cfb\u3092\u4f7f\u3046\u306e\u3067\u7279\u306b\u554f\u984c\u306a\u3057\n<\/p>\n<p>\n\u25a0Controller\n<\/p>\n<p>\n\/Store?id=10 \u3067\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u3088\u3046\u306b\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u3092\u4f5c\u6210\n<\/p>\n<p>\nin Controller\/StoreController.php\n<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nclass StoreController extends AppController {\r\n\tpublic function index() {\r\n\t\t$id = null;\r\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;];\r\n\r\n\t\tif ( $id != null ) {\r\n\t\t\t$this-&gt;set(&#039;Store&#039;,$this-&gt;Store-&gt;findAllById($id));\r\n\t\t} else {\r\n\t\t\t$this-&gt;set(&#039;Store&#039;, $this-&gt;Store-&gt;find(&#039;all&#039;,array(&#039;limit&#039;=&gt;&#039;100&#039;)));\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n<p>\n\u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u90e8\u5206\u306f\u3001$this-&gt;params[&#8216;url&#8217;][&#8216;id&#8217;] \u306e\u3088\u3046\u306b\u53d6\u5f97\u3067\u304d\u308b\u3002<br \/>\n\u305f\u3060\u3057\u3001?id=10 \u306e\u90e8\u5206\u304c\u6307\u5b9a\u3055\u308c\u3066\u3044\u306a\u3044\u5834\u5408\u306f\u3001\u30a8\u30e9\u30fc\u306b\u306a\u308b\u306e\u3067\u3001isset \u3067\u30c1\u30a7\u30c3\u30af\u3002\n<\/p>\n<p>\nfindAllById \u3092\u4f7f\u3063\u3066\u3044\u308b\u306e\u306f\u3001\u914d\u5217\u3092\u8fd4\u3057\u305f\u3044\u304b\u3089\u3002findById \u306b\u3059\u308b\u3068\u5358\u4f53\u306b\u306a\u308b\u3093\u3060\u3051\u3069\u3001View \u306e foreach \u3092\u5909\u66f4\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u300c\u9762\u5012\u306a\u306e\u3067\u300d\u30011\u4ef6\u306e\u5834\u5408\u3082\u914d\u5217\u306b\u3059\u308b\u305f\u3081\u3002\n<\/p>\n<p>\n\u25a0View\n<\/p>\n<p>\nfindAllById \u3092\u4f7f\u3063\u3066\u3044\u308b\u306e\u3067\u3001foreach \u306e\u3068\u3053\u308d\u306f\u66f8\u304d\u63db\u3048\u305a\u306b\u6e08\u3080\u3002\n<\/p>\n<p>\n\u25a0\u7d50\u679c\n<\/p>\n<p>\n\u6307\u5b9a\u3057\u305f ID \u306e 1\u4ef6\u3060\u3051\u304c\u8868\u793a\u3055\u308c\u308b\u3002\n<\/p>\n<p><a href='http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2013\/04\/wpid-dworkblogimage20130430_02org.jpg'><img border='0' src='http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2013\/04\/wpid-dworkblogimage20130430_02thum.jpg'\/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>findById \u3068\u304b findAllById \u3092\u4f7f\u3063\u3066 PK \u306e id \u3092\u4f7f\u3063\u3066\u53d6\u5f97\u3059\u308b\u30d1\u30bf\u30fc\u30f3 \u25a0Model find \u7cfb\u3092\u4f7f\u3046\u306e\u3067\u7279\u306b\u554f\u984c\u306a\u3057 \u25a0Controller \/Store?id=10 \u3067\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u3088\u3046 &hellip; <a href=\"http:\/\/www.moonmile.net\/blog\/archives\/4762\">\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-4762","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\/4762","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=4762"}],"version-history":[{"count":1,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/4762\/revisions"}],"predecessor-version":[{"id":4763,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/4762\/revisions\/4763"}],"wp:attachment":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/media?parent=4762"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/categories?post=4762"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/tags?post=4762"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}