回答編集履歴
3
コードのミス CommentsではなくCommentでした
answer
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
```php
|
7
7
|
<h2>Comments</h2>
|
8
8
|
<ul>
|
9
|
-
<?php foreach ($post['
|
9
|
+
<?php foreach ($post['Comment'] as $comment) : ?>
|
10
10
|
<li>
|
11
11
|
<?php
|
12
12
|
echo h($comment['body']);
|
2
default\.ctpの修正を戻したものを追記しました
answer
CHANGED
@@ -48,4 +48,69 @@
|
|
48
48
|
}
|
49
49
|
}
|
50
50
|
?>
|
51
|
+
```
|
52
|
+
|
53
|
+
default.ctp
|
54
|
+
```php
|
55
|
+
<?php
|
56
|
+
/**
|
57
|
+
*
|
58
|
+
* PHP 5
|
59
|
+
*
|
60
|
+
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
61
|
+
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
62
|
+
*
|
63
|
+
* Licensed under The MIT License
|
64
|
+
* For full copyright and license information, please see the LICENSE.txt
|
65
|
+
* Redistributions of files must retain the above copyright notice.
|
66
|
+
*
|
67
|
+
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
68
|
+
* @link http://cakephp.org CakePHP(tm) Project
|
69
|
+
* @package app.View.Layouts
|
70
|
+
* @since CakePHP(tm) v 0.10.0.1076
|
71
|
+
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
72
|
+
*/
|
73
|
+
$cakeDescription = __d('cake_dev', 'CakePHP: the rapid development php framework');
|
74
|
+
?>
|
75
|
+
<!DOCTYPE html>
|
76
|
+
<html>
|
77
|
+
<head>
|
78
|
+
<?php echo $this->Html->charset(); ?>
|
79
|
+
<title>
|
80
|
+
<?php echo $cakeDescription ?>:
|
81
|
+
<?php echo $title_for_layout; ?>
|
82
|
+
</title>
|
83
|
+
<?php
|
84
|
+
echo $this->Html->meta('icon');
|
85
|
+
|
86
|
+
echo $this->Html->css('cake.generic');
|
87
|
+
|
88
|
+
echo $this->fetch('meta');
|
89
|
+
echo $this->fetch('css');
|
90
|
+
echo $this->fetch('script');
|
91
|
+
?>
|
92
|
+
</head>
|
93
|
+
<body>
|
94
|
+
<div id="container">
|
95
|
+
<div id="header">
|
96
|
+
<h1><?php echo $this->Html->link($cakeDescription, 'http://cakephp.org'); ?></h1>
|
97
|
+
</div>
|
98
|
+
<div id="content">
|
99
|
+
|
100
|
+
<?php echo $this->Session->flash(); ?>
|
101
|
+
|
102
|
+
<?php echo $this->fetch('content'); ?>
|
103
|
+
</div>
|
104
|
+
<div id="footer">
|
105
|
+
<?php echo $this->Html->link(
|
106
|
+
$this->Html->image('cake.power.gif', array('alt' => $cakeDescription, 'border' => '0')),
|
107
|
+
'http://www.cakephp.org/',
|
108
|
+
array('target' => '_blank', 'escape' => false)
|
109
|
+
);
|
110
|
+
?>
|
111
|
+
</div>
|
112
|
+
</div>
|
113
|
+
<?php echo $this->element('sql_dump'); ?>
|
114
|
+
</body>
|
115
|
+
</html>
|
51
116
|
```
|
1
コード例を追加しましたので参考にしてください
answer
CHANGED
@@ -15,4 +15,37 @@
|
|
15
15
|
<?php endforeach; ?>
|
16
16
|
</ul>
|
17
17
|
```
|
18
|
+
|
19
|
+
---
|
20
|
+
|
18
|
-
|
21
|
+
PostsController.phpの実装例
|
22
|
+
```php
|
23
|
+
<?php
|
24
|
+
App::uses('AppController', 'Controller');
|
25
|
+
class PostsController extends AppController {
|
26
|
+
public $scaffold;
|
27
|
+
public $helper = array('HTML', 'Form');
|
28
|
+
|
29
|
+
public function index() {
|
30
|
+
$this->set('posts', $this->Post->find('all')); //$this->setでPosts変数へ代入。 $this->Post->fin('all')で記事を全て持ってくる。
|
31
|
+
$this->set('title_for_layout', '記事一覧'); //タイトルをセット
|
32
|
+
}
|
33
|
+
|
34
|
+
public function view($id = null) {
|
35
|
+
$this->Post->id = $id;
|
36
|
+
$this->set('post', $this->Post->read());
|
37
|
+
}
|
38
|
+
|
39
|
+
public function add() {
|
40
|
+
if ($this->request->is('post')) {
|
41
|
+
if ($this->Post->save($this->request->data)) {
|
42
|
+
$this->Session->setFlash('Success!');
|
43
|
+
$this->redirect(array('action' => 'index'));
|
44
|
+
} else {
|
45
|
+
$this->Session->setFlash('failed');
|
46
|
+
}
|
47
|
+
}
|
48
|
+
}
|
49
|
+
}
|
50
|
+
?>
|
51
|
+
```
|