{"id":207,"date":"2012-03-18T00:17:00","date_gmt":"2012-03-17T15:17:00","guid":{"rendered":"https:\/\/jikoman.sin-cos.com\/blog\/?p=207"},"modified":"2012-03-18T00:17:00","modified_gmt":"2012-03-17T15:17:00","slug":"cakephp_18","status":"publish","type":"post","link":"https:\/\/jikoman.sin-cos.com\/blog\/2012\/03\/cakephp_18\/","title":{"rendered":"CakePHP\u306e\u5fb3\u4e95\u304f\u3093\u3068\u798f\u7530\u304f\u3093"},"content":{"rendered":"<p><a href=\"http:\/\/book.cakephp.org\/2.0\/ja\/tutorials-and-examples\/blog\/blog.html\">http:\/\/book.cakephp.org\/2.0\/ja\/tutorials-and-examples\/blog\/blog.html<\/a>\u306e\u5fb3\u3001\u3001\u3001\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3092\u9032\u3081\u308b\u3002<\/p>\n<p>\u2019posts\u2019\u3068\u3044\u3046\u30c6\u30fc\u30d6\u30eb\u540d\u306b\u3057\u3066\u304a\u3051\u3070\u3001\u81ea\u52d5\u7684\u306bPost\u30e2\u30c7\u30eb\u304c\u547c\u3073\u51fa\u3055\u308c\u3001\u2019modified\u2019\u3068\u2019created\u2019\u3068\u3044\u3046\u30d5\u30a3\u30fc\u30eb\u30c9\u304c\u3042\u308b\u3068\u3001\u81ea\u52d5\u7684\u306bCake\u304c\u7ba1\u7406\u3059\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n\u307b\u3063\u307b\uff5e\u3001\u305d\u3046\u3044\u3046\u4e8b\u304b\u3002<br \/>\n\u3068\u3001\u3042\u3093\u307e\u308a\u5206\u304b\u3063\u3066\u3044\u306a\u3044\u306e\u3067\u3001\u3068\u308a\u3042\u3048\u305a \u66f8\u3044\u3066\u3042\u308b\u30b5\u30f3\u30d7\u30eb\u3092\u30b3\u30d4\u30da\u3057\u3066\u307f\u308b\u3002<br \/>\n\u3061\u306a\u307f\u306b\u3001\u30d5\u30a1\u30a4\u30eb\u69cb\u6210\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308b\u3002<br \/>\n\/app<br \/>\n&nbsp;&nbsp;\/Model<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;\/Post.php<br \/>\n&nbsp;&nbsp;\/Controller<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;\/PostsController.php<br \/>\n&nbsp;&nbsp;\/Posts<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;\/index.ctp<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;\/view.ctp<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;\/add.ctp<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;\/edit.ctp<br \/>\n\/app\/Model\/Post.php<br \/>\n&lt;?php<br \/>\nclass Post extends AppModel {<br \/>\n public $name = &#8216;Post&#8217;;<\/p>\n<p> public $validate = array(<br \/>\n  &#8216;title&#8217; =&gt; array(<br \/>\n   &#8216;rule&#8217; =&gt; &#8216;notEmpty&#8217;<br \/>\n  ),<br \/>\n  &#8216;body&#8217; =&gt; array(<br \/>\n   &#8216;rule&#8217; =&gt; &#8216;notEmpty&#8217;<br \/>\n  )<br \/>\n );<br \/>\n}<br \/>\n\/app\/Controller\/PostsController.php<br \/>\n&lt;?php<br \/>\nclass PostsController extends AppController {<br \/>\n public $name = &#8216;Posts&#8217;;<br \/>\n public $helpers = array(&#8216;Html&#8217;, &#8216;Form&#8217;);<br \/>\n public $components = array(&#8216;Session&#8217;);<\/p>\n<p> public function index() {<br \/>\n  $this-&gt;set(&#8216;posts&#8217;, $this-&gt;Post-&gt;find(&#8216;all&#8217;));<br \/>\n }<\/p>\n<p> public function view($id) {<br \/>\n  $this-&gt;Post-&gt;id = $id;<br \/>\n  $this-&gt;set(&#8216;post&#8217;, $this-&gt;Post-&gt;read());<\/p>\n<p> }<\/p>\n<p> public function add() {<br \/>\n  if ($this-&gt;request-&gt;is(&#8216;post&#8217;)) {<br \/>\n   if ($this-&gt;Post-&gt;save($this-&gt;request-&gt;data)) {<br \/>\n    $this-&gt;Session-&gt;setFlash(&#8216;Your post has been saved.&#8217;);<br \/>\n    $this-&gt;redirect(array(&#8216;action&#8217; =&gt; &#8216;index&#8217;));<br \/>\n   } else {<br \/>\n    $this-&gt;Session-&gt;setFlash(&#8216;Unable to add your post.&#8217;);<br \/>\n   }<br \/>\n  }<br \/>\n }<\/p>\n<p> function edit($id = null) {<br \/>\n  $this-&gt;Post-&gt;id = $id;<br \/>\n  if ($this-&gt;request-&gt;is(&#8216;get&#8217;)) {<br \/>\n   $this-&gt;request-&gt;data = $this-&gt;Post-&gt;read();<br \/>\n  } else {<br \/>\n   if ($this-&gt;Post-&gt;save($this-&gt;request-&gt;data)) {<br \/>\n    $this-&gt;Session-&gt;setFlash(&#8216;Your post has been updated.&#8217;);<br \/>\n    $this-&gt;redirect(array(&#8216;action&#8217; =&gt; &#8216;index&#8217;));<br \/>\n   } else {<br \/>\n    $this-&gt;Session-&gt;setFlash(&#8216;Unable to update your post.&#8217;);<br \/>\n   }<br \/>\n  }<br \/>\n }<\/p>\n<p> function delete($id) {<br \/>\n  if ($this-&gt;request-&gt;is(&#8216;get&#8217;)) {<br \/>\n   throw new MethodNotAllowedException();<br \/>\n  }<br \/>\n  if ($this-&gt;Post-&gt;delete($id)) {<br \/>\n   $this-&gt;Session-&gt;setFlash(&#8216;The post with id: &#8216; . $id . &#8216; has been deleted.&#8217;);<br \/>\n   $this-&gt;redirect(array(&#8216;action&#8217; =&gt; &#8216;index&#8217;));<br \/>\n  }<br \/>\n }<br \/>\n}<br \/>\n\/app\/View\/Posts\u30d5\u30a9\u30eb\u30c0\u3092\u4f5c\u6210\u3057\u3066\u3001<br \/>\n\/app\/View\/Posts\/index.ctp<br \/>\n&lt;h1&gt;Blog posts&lt;\/h1&gt;<br \/>\n&lt;p&gt;&lt;?php echo $this-&gt;Html-&gt;link(&#8216;Add Post&#8217;, array(&#8216;action&#8217; =&gt; &#8216;add&#8217;)); ?&gt;&lt;\/p&gt;<br \/>\n&lt;table&gt;<br \/>\n &lt;tr&gt;<br \/>\n  &lt;th&gt;Id&lt;\/th&gt;<br \/>\n  &lt;th&gt;Title&lt;\/th&gt;<br \/>\n    &lt;th&gt;Actions&lt;\/th&gt;<br \/>\n  &lt;th&gt;Created&lt;\/th&gt;<br \/>\n &lt;\/tr&gt;<\/p>\n<p>&lt;!&#8211; \u3053\u3053\u3067$posts\u914d\u5217\u3092\u30eb\u30fc\u30d7\u3057\u3066\u3001\u6295\u7a3f\u60c5\u5831\u3092\u8868\u793a &#8211;&gt;<\/p>\n<p> &lt;?php foreach ($posts as $post): ?&gt;<br \/>\n &lt;tr&gt;<br \/>\n  &lt;td&gt;&lt;?php echo $post[&#8216;Post&#8217;][&#8216;id&#8217;]; ?&gt;&lt;\/td&gt;<br \/>\n  &lt;td&gt;<br \/>\n   &lt;?php echo $this-&gt;Html-&gt;link($post[&#8216;Post&#8217;][&#8216;title&#8217;], array(&#8216;action&#8217; =&gt; &#8216;view&#8217;, $post[&#8216;Post&#8217;][&#8216;id&#8217;]));?&gt;<br \/>\n  &lt;\/td&gt;<br \/>\n  &lt;td&gt;<br \/>\n   &lt;?php echo $this-&gt;Form-&gt;postLink(<br \/>\n    &#8216;Delete&#8217;,<br \/>\n    array(&#8216;action&#8217; =&gt; &#8216;delete&#8217;, $post[&#8216;Post&#8217;][&#8216;id&#8217;]),<br \/>\n    array(&#8216;confirm&#8217; =&gt; &#8216;Are you sure?&#8217;));<br \/>\n   ?&gt;<br \/>\n   &lt;?php echo $this-&gt;Html-&gt;link(&#8216;Edit&#8217;, array(&#8216;action&#8217; =&gt; &#8216;edit&#8217;, $post[&#8216;Post&#8217;][&#8216;id&#8217;]));?&gt;<br \/>\n  &lt;\/td&gt;<br \/>\n  &lt;td&gt;<br \/>\n   &lt;?php echo $post[&#8216;Post&#8217;][&#8216;created&#8217;]; ?&gt;<br \/>\n  &lt;\/td&gt;<br \/>\n &lt;\/tr&gt;<br \/>\n &lt;?php endforeach; ?&gt;<br \/>\n&lt;\/table&gt;<\/p>\n<p>\/app\/View\/Posts\/view.ctp<br \/>\n&lt;h1&gt;&lt;?php echo $post[&#8216;Post&#8217;][&#8216;title&#8217;]?&gt;&lt;\/h1&gt;<br \/>\n&lt;p&gt;&lt;small&gt;Created: &lt;?php echo $post[&#8216;Post&#8217;][&#8216;created&#8217;]?&gt;&lt;\/small&gt;&lt;\/p&gt;<br \/>\n&lt;p&gt;&lt;?php echo $post[&#8216;Post&#8217;][&#8216;body&#8217;]?&gt;&lt;\/p&gt;<br \/>\n\/app\/View\/Posts\/add.ctp<br \/>\n&lt;h1&gt;Add Post&lt;\/h1&gt;<br \/>\n&lt;?php<br \/>\n echo $this-&gt;Form-&gt;create(&#8216;Post&#8217;);<br \/>\n echo $this-&gt;Form-&gt;input(&#8216;title&#8217;);<br \/>\n echo $this-&gt;Form-&gt;input(&#8216;body&#8217;, array(&#8216;rows&#8217; =&gt; &#8216;3&#8217;));<br \/>\n echo $this-&gt;Form-&gt;end(&#8216;Save Post&#8217;);<br \/>\n\/app\/View\/Posts\/edit.ctp<br \/>\n&lt;h1&gt;Edit Post&lt;\/h1&gt;<br \/>\n&lt;?php<br \/>\n echo $this-&gt;Form-&gt;create(&#8216;Post&#8217;, array(&#8216;action&#8217; =&gt; &#8216;edit&#8217;));<br \/>\n echo $this-&gt;Form-&gt;input(&#8216;title&#8217;);<br \/>\n echo $this-&gt;Form-&gt;input(&#8216;body&#8217;, array(&#8216;rows&#8217; =&gt; &#8216;3&#8217;));<br \/>\n echo $this-&gt;Form-&gt;input(&#8216;id&#8217;, array(&#8216;type&#8217; =&gt; &#8216;hidden&#8217;));<br \/>\n echo $this-&gt;Form-&gt;end(&#8216;Save Post&#8217;);<br \/>\n\u3067\u3001\u3068\u308a\u3042\u3048\u305a\u3001\u8868\u793a\u3057\u3066\u30c6\u30b9\u30c8\u3002<br \/>\nhttp:\/\/localhost\/cakephp\/posts<br \/>\n\u3067\u3082\u3001\u6587\u5b57\u5316\u3051\u3002\u3002\u3002<br \/>\n\/app\/Config\/database.php\u306b\u6b21\u306e\u4e00\u884c\u8ffd\u52a0\u3067\u89e3\u6c7a\uff01<br \/>\n  &#8216;encoding&#8217; =&gt; &#8216;utf8&#8217;,<\/p>\n","protected":false},"excerpt":{"rendered":"<p>http:\/\/book.cakephp.org\/2.0\/ja\/tutorials-and-examples\/blog\/blog.html\u306e\u5fb3\u3001\u3001\u3001\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3092\u9032\u3081\u308b\u3002 \u2019posts\u2019\u3068\u3044\u3046\u30c6\u30fc\u30d6\u30eb\u540d\u306b\u3057\u3066\u304a\u3051\u3070\u3001\u81ea\u52d5 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[130],"tags":[],"class_list":["post-207","post","type-post","status-publish","format-standard","hentry","category-130"],"_links":{"self":[{"href":"https:\/\/jikoman.sin-cos.com\/blog\/wp-json\/wp\/v2\/posts\/207","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jikoman.sin-cos.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jikoman.sin-cos.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jikoman.sin-cos.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jikoman.sin-cos.com\/blog\/wp-json\/wp\/v2\/comments?post=207"}],"version-history":[{"count":0,"href":"https:\/\/jikoman.sin-cos.com\/blog\/wp-json\/wp\/v2\/posts\/207\/revisions"}],"wp:attachment":[{"href":"https:\/\/jikoman.sin-cos.com\/blog\/wp-json\/wp\/v2\/media?parent=207"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jikoman.sin-cos.com\/blog\/wp-json\/wp\/v2\/categories?post=207"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jikoman.sin-cos.com\/blog\/wp-json\/wp\/v2\/tags?post=207"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}