回答編集履歴

4

追記(コード追加)

2016/01/14 08:58

投稿

coba-coba
coba-coba

スコア1409

test CHANGED
@@ -44,7 +44,7 @@
44
44
 
45
45
 
46
46
 
47
- 追記:(コード追加)
47
+ 追記:(コード追加)(コントローラー)
48
48
 
49
49
  ---
50
50
 
@@ -107,3 +107,203 @@
107
107
 
108
108
 
109
109
  ```
110
+
111
+
112
+
113
+ 追記:(コード追加)(ビュー)
114
+
115
+ ---
116
+
117
+ [Replies/add.ctp]
118
+
119
+ ```PHP
120
+
121
+ <div class="replies form">
122
+
123
+ <?php echo $this->Form->create('Reply'); ?>
124
+
125
+ <fieldset>
126
+
127
+ <legend><?php echo __('Add Reply'); ?></legend>
128
+
129
+ <?php
130
+
131
+ echo $this->Form->input('tweet_id');
132
+
133
+ echo $this->Form->input('user_id');
134
+
135
+ echo $this->Form->input('reply');
136
+
137
+ ?>
138
+
139
+ </fieldset>
140
+
141
+ <?php echo $this->Form->end(__('Submit')); ?>
142
+
143
+ </div>
144
+
145
+ <div class="actions">
146
+
147
+ <h3><?php echo __('Actions'); ?></h3>
148
+
149
+ <ul>
150
+
151
+
152
+
153
+ <li><?php echo $this->Html->link(__('List Replies'), array('action' => 'index')); ?></li>
154
+
155
+ <li><?php echo $this->Html->link(__('List Tweets'), array('controller' => 'tweets', 'action' => 'index')); ?> </li>
156
+
157
+ <li><?php echo $this->Html->link(__('New Tweet'), array('controller' => 'tweets', 'action' => 'add')); ?> </li>
158
+
159
+ <li><?php echo $this->Html->link(__('List Users'), array('controller' => 'users', 'action' => 'index')); ?> </li>
160
+
161
+ <li><?php echo $this->Html->link(__('New User'), array('controller' => 'users', 'action' => 'add')); ?> </li>
162
+
163
+ </ul>
164
+
165
+ </div>
166
+
167
+ ```
168
+
169
+
170
+
171
+ [Tweets/view.ctp]
172
+
173
+ ```PHP
174
+
175
+ <div class="tweets view">
176
+
177
+ <h2><?php echo __('Tweet'); ?></h2>
178
+
179
+ <dl>
180
+
181
+ <dt><?php echo __('Id'); ?></dt>
182
+
183
+ <dd>
184
+
185
+ <?php echo h($tweet['Tweet']['id']); ?>
186
+
187
+ &nbsp;
188
+
189
+ </dd>
190
+
191
+ <dt><?php echo __('User'); ?></dt>
192
+
193
+ <dd>
194
+
195
+ <?php echo $this->Html->link($tweet['User']['username'], array('controller' => 'users', 'action' => 'view', $tweet['User']['id'])); ?>
196
+
197
+ &nbsp;
198
+
199
+ </dd>
200
+
201
+ <dt><?php echo __('Tweet'); ?></dt>
202
+
203
+ <dd>
204
+
205
+ <?php echo h($tweet['Tweet']['tweet']); ?>
206
+
207
+ &nbsp;
208
+
209
+ </dd>
210
+
211
+ </dl>
212
+
213
+ </div>
214
+
215
+ <div class="actions">
216
+
217
+ <h3><?php echo __('Actions'); ?></h3>
218
+
219
+ <ul>
220
+
221
+ <li><?php echo $this->Html->link(__('Edit Tweet'), array('action' => 'edit', $tweet['Tweet']['id'])); ?> </li>
222
+
223
+ <li><?php echo $this->Form->postLink(__('Delete Tweet'), array('action' => 'delete', $tweet['Tweet']['id']), array('confirm' => __('Are you sure you want to delete # %s?', $tweet['Tweet']['id']))); ?> </li>
224
+
225
+ <li><?php echo $this->Html->link(__('List Tweets'), array('action' => 'index')); ?> </li>
226
+
227
+ <li><?php echo $this->Html->link(__('New Tweet'), array('action' => 'add')); ?> </li>
228
+
229
+ <li><?php echo $this->Html->link(__('List Users'), array('controller' => 'users', 'action' => 'index')); ?> </li>
230
+
231
+ <li><?php echo $this->Html->link(__('New User'), array('controller' => 'users', 'action' => 'add')); ?> </li>
232
+
233
+ <li><?php echo $this->Html->link(__('List Replies'), array('controller' => 'replies', 'action' => 'index')); ?> </li>
234
+
235
+ <li><?php echo $this->Html->link(__('New Reply'), array('controller' => 'replies', 'action' => 'add')); ?> </li>
236
+
237
+ </ul>
238
+
239
+ </div>
240
+
241
+ <div class="related">
242
+
243
+ <h3><?php echo __('Related Replies'); ?></h3>
244
+
245
+ <?php if (!empty($tweet['Reply'])): ?>
246
+
247
+ <table cellpadding = "0" cellspacing = "0">
248
+
249
+ <tr>
250
+
251
+ <th><?php echo __('Id'); ?></th>
252
+
253
+ <th><?php echo __('Tweet Id'); ?></th>
254
+
255
+ <th><?php echo __('User Id'); ?></th>
256
+
257
+ <th><?php echo __('Reply'); ?></th>
258
+
259
+ <th class="actions"><?php echo __('Actions'); ?></th>
260
+
261
+ </tr>
262
+
263
+ <?php foreach ($tweet['Reply'] as $reply): ?>
264
+
265
+ <tr>
266
+
267
+ <td><?php echo $reply['id']; ?></td>
268
+
269
+ <td><?php echo $reply['tweet_id']; ?></td>
270
+
271
+ <td><?php echo $reply['user_id']; ?></td>
272
+
273
+ <td><?php echo $reply['reply']; ?></td>
274
+
275
+ <td class="actions">
276
+
277
+ <?php echo $this->Html->link(__('View'), array('controller' => 'replies', 'action' => 'view', $reply['id'])); ?>
278
+
279
+ <?php echo $this->Html->link(__('Edit'), array('controller' => 'replies', 'action' => 'edit', $reply['id'])); ?>
280
+
281
+ <?php echo $this->Form->postLink(__('Delete'), array('controller' => 'replies', 'action' => 'delete', $reply['id']), array('confirm' => __('Are you sure you want to delete # %s?', $reply['id']))); ?>
282
+
283
+ </td>
284
+
285
+ </tr>
286
+
287
+ <?php endforeach; ?>
288
+
289
+ </table>
290
+
291
+ <?php endif; ?>
292
+
293
+
294
+
295
+ <div class="actions">
296
+
297
+ <ul>
298
+
299
+ <li><?php echo $this->Html->link(__('New Reply'), array('controller' => 'replies', 'action' => 'add')); ?> </li>
300
+
301
+ </ul>
302
+
303
+ </div>
304
+
305
+ </div>
306
+
307
+
308
+
309
+ ```

3

レイアウト修正

2016/01/14 08:58

投稿

coba-coba
coba-coba

スコア1409

test CHANGED
@@ -10,7 +10,11 @@
10
10
 
11
11
 
12
12
 
13
+
14
+
13
15
  追記:(画像追加)
16
+
17
+ ---
14
18
 
15
19
  ![イメージ説明](044f2aa2a4fd377931c48d2b244c5bb0.jpeg)
16
20
 
@@ -38,7 +42,11 @@
38
42
 
39
43
 
40
44
 
45
+
46
+
41
47
  追記:(コード追加)
48
+
49
+ ---
42
50
 
43
51
  [RepliesController.php]の[RepliesController], [addアクション]
44
52
 

2

追記(コード追加)

2016/01/14 08:52

投稿

coba-coba
coba-coba

スコア1409

test CHANGED
@@ -35,3 +35,67 @@
35
35
  ![イメージ説明](c74336ca213155d05f760cc05bb00e36.jpeg)
36
36
 
37
37
 
38
+
39
+
40
+
41
+ 追記:(コード追加)
42
+
43
+ [RepliesController.php]の[RepliesController], [addアクション]
44
+
45
+ ```PHP
46
+
47
+ public function add() {
48
+
49
+ if ($this->request->is('post')) {
50
+
51
+ $this->Reply->create();
52
+
53
+ if ($this->Reply->save($this->request->data)) {
54
+
55
+ $this->Flash->success(__('The reply has been saved.'));
56
+
57
+ return $this->redirect(array('action' => 'index'));
58
+
59
+ } else {
60
+
61
+ $this->Flash->error(__('The reply could not be saved. Please, try again.'));
62
+
63
+ }
64
+
65
+ }
66
+
67
+ $tweets = $this->Reply->Tweet->find('list');
68
+
69
+ $users = $this->Reply->User->find('list');
70
+
71
+ $this->set(compact('tweets', 'users'));
72
+
73
+ }
74
+
75
+
76
+
77
+ ```
78
+
79
+
80
+
81
+ [TweetsController.php]、[TweetsController]、[viewアクション]
82
+
83
+ ```PHP
84
+
85
+ public function view($id = null) {
86
+
87
+ if (!$this->Tweet->exists($id)) {
88
+
89
+ throw new NotFoundException(__('Invalid tweet'));
90
+
91
+ }
92
+
93
+ $options = array('conditions' => array('Tweet.' . $this->Tweet->primaryKey => $id));
94
+
95
+ $this->set('tweet', $this->Tweet->find('first', $options));
96
+
97
+ }
98
+
99
+
100
+
101
+ ```

1

追記(画像追加)

2016/01/14 08:19

投稿

coba-coba
coba-coba

スコア1409

test CHANGED
@@ -7,3 +7,31 @@
7
7
 
8
8
 
9
9
  そうすると、TweetsController.phpのreplyメソッドにidが渡され、投稿を取得してくれるのではないでしょうか。
10
+
11
+
12
+
13
+ 追記:(画像追加)
14
+
15
+ ![イメージ説明](044f2aa2a4fd377931c48d2b244c5bb0.jpeg)
16
+
17
+
18
+
19
+
20
+
21
+ ↓ 上記画像のSubmitボタンを押したら、下記画像が表示される。
22
+
23
+ ↓ (上記画像では、ユーザーとツイートを特定するIDを渡していませんが、
24
+
25
+ ↓ IDを渡せば特定できます。)
26
+
27
+ ↓ (このアプリケーションでは、Submit後のページ遷移は実装していませんが、
28
+
29
+ ↓ リダイレクトしてツイートのIDを渡すだけです。
30
+
31
+
32
+
33
+
34
+
35
+ ![イメージ説明](c74336ca213155d05f760cc05bb00e36.jpeg)
36
+
37
+