{"id":4770,"date":"2013-04-30T15:41:42","date_gmt":"2013-04-29T21:41:42","guid":{"rendered":"http:\/\/www.moonmile.net\/blog\/?p=4770"},"modified":"2013-04-30T15:42:02","modified_gmt":"2013-04-30T06:42:02","slug":"cakephp-%e6%a4%9c%e7%b4%a2id%e3%82%92url%e3%81%ab%e5%9f%8b%e3%82%81%e8%be%bc%e3%82%93%e3%81%a7%e6%a4%9c%e7%b4%a2%e3%81%95%e3%81%9b%e3%82%8b","status":"publish","type":"post","link":"http:\/\/www.moonmile.net\/blog\/archives\/4770","title":{"rendered":"[CakePHP] \u691c\u7d22ID\u3092URL\u306b\u57cb\u3081\u8fbc\u3093\u3067\u691c\u7d22\u3055\u305b\u308b"},"content":{"rendered":"<p>\nfindAllById \u3092\u4f7f\u3063\u3066\u3001\u691c\u7d22\u3057\u3066\u53d6\u5f97\u3059\u308b\u30d1\u30bf\u30fc\u30f3\u3060\u304c\u3001\/Store?id=10 \u3067\u306f\u306a\u304f\u3066\u3001\/Store\/10 \u306e\u3088\u3046\u306b\u691c\u7d22\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\u3002\n<\/p>\n<p>\n\u25a0Model\n<\/p>\n<p>\nfind \u7cfb\u3092\u4f7f\u3046\u306e\u3067\u5909\u66f4\u306a\u3057\n<\/p>\n<p>\n\u25a0Controller\n<\/p>\n<p>\n\/Store\/10 \u3067\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u3088\u3046\u306b\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u3092\u4f5c\u6210&#8230;\u3057\u305f\u3044\u306e\u3060\u304c\u3001\u3067\u304d\u306a\u3044\u306e\u3067\u3001\/Store\/index\/10 \u3067\u30a2\u30af\u30bb\u30b9\u3059\u308b\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($id=null) {\r\n\t\t$group = 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\t\tif (isset($this-&gt;params&#x5B;&#039;url&#039;]&#x5B;&#039;group&#039;])) $group = $this-&gt;params&#x5B;&#039;url&#039;]&#x5B;&#039;group&#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 if ( $group != null ) {\r\n\t\t\t$this-&gt;set(&#039;Store&#039;,$this-&gt;Store-&gt;findAllByAreagroupid($group));\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>\nindex \u30e1\u30bd\u30c3\u30c9\u306e\u5f15\u304d\u6570\u306b $id \u3092\u8ffd\u52a0\u3059\u308b\u3060\u3051\u3002<br \/>\n\u6307\u5b9a\u3055\u308c\u306a\u3044\u5834\u5408\u306b\u3082\u5bfe\u5fdc\u3067\u304d\u308b\u3088\u3046\u306b\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u5024\u3092 null \u306b\u3057\u3066\u304a\u304f\u3002\n<\/p>\n<p>\n\/Store\/10 \u3067\u30a2\u30af\u30bb\u30b9\u3057\u3088\u3046\u3068\u3059\u308b\u3068\u3001\u300c10 \u3068\u3044\u3046\u540d\u524d\u306e\u30e1\u30bd\u30c3\u30c9\u304c\u306a\u3044\u300d\u3068\u3044\u3046\u30a8\u30e9\u30fc\u304c\u51fa\u308b\u306e\u3067\u3001\/Store\/index\/10 \u3067\u30a2\u30af\u30bb\u30b9\u3092\u3059\u308b\u3002\u3053\u306e\u5834\u5408\u3001\/Store\/select\/10 \u306e\u3088\u3046\u306b\u30e1\u30bd\u30c3\u30c9\u540d\u3092\u5909\u3048\u308b\u307b\u3046\u304c\u30d9\u30bf\u30fc\u304b\u3068\u3002<br \/>\n\u4eca\u56de\u306f\u3001Web API \u306a\u306e\u3067\u3001\/Store?id=10 \u5f62\u5f0f\u3067\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3088\u3046\u306b\u3057\u3088\u3046\u3002\n<\/p>\n<p>\n\u25a0View\n<\/p>\n<p>\n\u623b\u308a\u5024\u306f\u914d\u5217\u306b\u306a\u308b\u306e\u3067\u3001foreach \u306e\u3068\u3053\u308d\u306f\u305d\u306e\u307e\u307e\u3067\u3002\n<\/p>\n<p>\n\u25a0\u7d50\u679c\n<\/p>\n<p>\n\u6307\u5b9a\u3057\u305fID\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_04org.jpg'><img border='0' src='http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2013\/04\/wpid-dworkblogimage20130430_04thum.jpg'\/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>findAllById \u3092\u4f7f\u3063\u3066\u3001\u691c\u7d22\u3057\u3066\u53d6\u5f97\u3059\u308b\u30d1\u30bf\u30fc\u30f3\u3060\u304c\u3001\/Store?id=10 \u3067\u306f\u306a\u304f\u3066\u3001\/Store\/10 \u306e\u3088\u3046\u306b\u691c\u7d22\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\u3002 \u25a0Model find \u7cfb\u3092\u4f7f\u3046\u306e\u3067\u5909\u66f4\u306a\u3057 \u25a0Controlle &hellip; <a href=\"http:\/\/www.moonmile.net\/blog\/archives\/4770\">\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-4770","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\/4770","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=4770"}],"version-history":[{"count":1,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/4770\/revisions"}],"predecessor-version":[{"id":4771,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/4770\/revisions\/4771"}],"wp:attachment":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/media?parent=4770"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/categories?post=4770"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/tags?post=4770"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}