{"id":4793,"date":"2013-04-30T22:32:18","date_gmt":"2013-04-30T04:32:18","guid":{"rendered":"http:\/\/www.moonmile.net\/blog\/?p=4793"},"modified":"2013-04-30T22:32:38","modified_gmt":"2013-04-30T13:32:38","slug":"cakephp-%e3%82%bb%e3%83%83%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\/4793","title":{"rendered":"[CakePHP] \u30bb\u30c3\u30b7\u30e7\u30f3\u3092\u5229\u7528\u3059\u308b"},"content":{"rendered":"<p>\u3082\u3068\u3082\u3068 PHP \u306b\u306f $_SESSION \u304c\u3042\u308b\u306e\u3067\u3001\u305d\u308c\u3092\u5229\u7528\u3059\u308c\u3070\u3088\u3044\u306e\u3060\u304c\u3001CakePHP \u306f $this-&gt;Session \u3068\u3044\u3046\u3046\u5f62\u3067\u7528\u610f\u3055\u308c\u3066\u3044\u308b\u3002<\/p>\n<p>\u30bb\u30c3\u30b7\u30e7\u30f3 ? CakePHP Cookbook v2.x documentation<br \/>\n<a href=\"http:\/\/book.cakephp.org\/2.0\/ja\/core-libraries\/components\/sessions.html\">http:\/\/book.cakephp.org\/2.0\/ja\/core-libraries\/components\/sessions.html<\/a><\/p>\n<p>\u6b8b\u5ff5\u306a\u304c\u3089\u3001$_SESSION \u3068 $this-&gt;Session \u3068\u4e92\u63db\u6027\u306f\u306a\u3044\u6a21\u69d8\u3002\u4ed6\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u3068\u306e\u3084\u308a\u53d6\u308a\u3092\u3059\u308b\u306a\u3089\u3070\u3001$_SESSION \u3092\u4f7f\u3046\u3068\u826f\u3044\u3002<\/p>\n<p>\u25a0Model<\/p>\n<p>Model \u306f\u305d\u306e\u307e\u307e<\/p>\n<p>\u25a0Controller<\/p>\n<p>sess \u30e1\u30bd\u30c3\u30c9\u3067 id \u3092\u4fdd\u5b58\u3057\u3066\u304a\u3044\u3066\u3001index \u3067\u691c\u7d22\u7d50\u679c\u3092\u51fa\u3059\u3068\u3044\u3046\u5177\u5408\u3002<\/p>\n<p>in Controller\/TestController.php<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n\tpublic function index($id=null) {\r\n\t\tif ($id==null) {\r\n\t\t\t\/\/ \u30bb\u30c3\u30b7\u30e7\u30f3\u5185\u306eID\u3092\u4f7f\u3046\r\n\t\t\t$id = $this-&gt;Session-&gt;read(&amp;quot;Test.id&amp;quot;);\r\n\t\t\t\/\/ session_start();\r\n\t\t\t\/\/ $id = $_SESSION&#x5B;&#039;Test.id&#039;];\r\n\t\t}\r\n\t\tif (isset($this-&gt;params&#x5B;&#039;url&#039;]&#x5B;&#039;id&#039;]))\r\n\t\t\t$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;Test&#039;,$this-&gt;Test-&gt;findAllById($id));\r\n\t\t} else {\r\n\t\t\t$this-&gt;set(&#039;Test&#039;,$this-&gt;Test-&gt;find(&#039;all&#039;));\r\n\t\t}\r\n\t}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n\t\/\/ \u30bb\u30c3\u30b7\u30e7\u30f3\u3092\u4fdd\u5b58\r\n\tpublic function sess($id=null) {\r\n\t\t$this-&gt;Session-&gt;write(&amp;quot;Test.id&amp;quot;,$id);\r\n\t\t\/\/ session_start();\r\n\t\t\/\/ $_SESSION&#x5B;&#039;Test.id&#039;] = $id ;\r\n\t\t$this-&gt;redirect(&#039;.&#039;);\r\n\t}\r\n<\/pre>\n<p>\/Test\/sess\/7 \u3067 URL \u3092\u547c\u3073\u51fa\u3059\u3068\u3001\/Test\/index\/7 \u3068\u540c\u3058\u3088\u3046\u306a\u547c\u3073\u51fa\u3057\u306b\u306a\u308b\uff08\u5185\u90e8\u3067 redirect \u3057\u3066\u3044\u308b\uff09\u3002\u3053\u306e\u3068\u304d\u306b\u3001sess \u304b\u3089 index \u306b\u6e21\u3059\u305f\u3081\u306b $this-&gt;Session \u3092\u4f7f\u3063\u3066\u3044\u308b\u3002\u3053\u306e\u30d1\u30bf\u30fc\u30f3\u3060\u3068\u3001\u76f4\u63a5\u30e1\u30bd\u30c3\u30c9\u547c\u3073\u51fa\u3057\u3092\u3057\u305f\u307b\u3046\u304c\u5b89\u5168\u304b&#8230;\u307e\u3042\u3001URL \u304c \/Test\/ \u306b\u306a\u308b\u306e\u3067\u3001\u305d\u308c\u306f\u305d\u308c\u3067 ok\uff08\u30a2\u30c9\u30ec\u30b9\u304c\u96a0\u853d\u5316\u3055\u308c\u308b\u3068\u3044\u3046\u610f\u5473\u3067\uff09\u3002<\/p>\n<p>$_SESSION[&#8216;Test.id&#8217;] \u3067\u3082\u540c\u3058\u3053\u3068\u304c\u3067\u304d\u308b\u3002\u6b8b\u5ff5\u306a\u304c\u3089\u3001$_SESSION[&#8216;Test.id&#8217;] \u3068 $this-&gt;Session-&gt;read(&#8220;Test.id&#8221;); \u306f\u7570\u306a\u308b\u5024\u3092\u793a\u3057\u3066\u3044\u308b\u3002\u3053\u308c\u306f\u540d\u524d\u3092\u300cid\u300d\u3068\u304b\u306b\u3057\u3066\u3082\u30c0\u30e1\u3060\u3063\u305f\u3002<\/p>\n<p>\u25a0View<\/p>\n<p>View \u306f\u540c\u3058<\/p>\n<p>\u25a0\u7d50\u679c<\/p>\n<p>\/Test\/sess\/7 \u3067\u547c\u3073\u51fa\u3059\u3068\u3001$this-&gt;Session \u306b\u4fdd\u5b58\u3055\u308c\u3066 index \u3067\u53c2\u7167\u3055\u308c\u308b\u3002<\/p>\n<p><a href=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2013\/04\/wpid-dworkblogimage20130430_09org.jpg\"><img decoding=\"async\" src=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2013\/04\/wpid-dworkblogimage20130430_09thum.jpg\" border=\"0\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3082\u3068\u3082\u3068 PHP \u306b\u306f $_SESSION \u304c\u3042\u308b\u306e\u3067\u3001\u305d\u308c\u3092\u5229\u7528\u3059\u308c\u3070\u3088\u3044\u306e\u3060\u304c\u3001CakePHP \u306f $this-&gt;Session \u3068\u3044\u3046\u3046\u5f62\u3067\u7528\u610f\u3055\u308c\u3066\u3044\u308b\u3002 \u30bb\u30c3\u30b7\u30e7\u30f3 ? CakePHP Cookbook  &hellip; <a href=\"http:\/\/www.moonmile.net\/blog\/archives\/4793\">\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-4793","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\/4793","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=4793"}],"version-history":[{"count":1,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/4793\/revisions"}],"predecessor-version":[{"id":4794,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/4793\/revisions\/4794"}],"wp:attachment":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/media?parent=4793"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/categories?post=4793"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/tags?post=4793"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}