質問するログイン新規登録

質問編集履歴

8

内容の修正

2016/09/07 13:03

投稿

sort_merge
sort_merge

スコア16

title CHANGED
File without changes
body CHANGED
@@ -355,4 +355,31 @@
355
355
  ![イメージ説明](48b451e9ce99c813796ff938639cc4c2.png)
356
356
 
357
357
  /posts/view/1にアクセスした際のエラー画像
358
- ![イメージ説明](79e80441af064052b7f35226d1aaa2ac.png)
358
+ ![イメージ説明](79e80441af064052b7f35226d1aaa2ac.png)
359
+
360
+ icchiさん修正前のview.ctpを実装した際のブラウザの画像(エラー含む)
361
+
362
+ ![![イメージ説明](b922ba4516245e2358e6a2dd5171872b.png)説明](a0c676fb952eb45baa39e5bec69271db.png)](7eef62bc967560326603bd36e95c7442.png)
363
+
364
+ icchiさん修正後のview.ctpを実装した際のブラウザ
365
+ の画像(エラー含む)
366
+
367
+ ![イメージ説明](ac695339d1574a8aa0e7af59543240ad.png)
368
+
369
+ 修正前と修正後両方を足したview.ctpを実装した際のブラウザ
370
+ の画像(エラー含む)
371
+
372
+ ![イメージ説明](93ece97d374cb244e28e7741e367f477.png)
373
+
374
+ 修正前の実装で出たエラーFormHelper.phpのコードを載せようとしたところ、字数オーバーになってしまったので、エラーに関する行を載せさせていただきます。
375
+ その行だけではわからないという場合は教えてください。
376
+
377
+ FormHelper.phpのエラーに関するソースコード
378
+ ```
379
+ if (isset($options['action'])) {
380
+ trigger_error('Using key `action` is deprecated, use `url` directly instead.', E_USER_DEPRECATED);
381
+ }
382
+ ```
383
+
384
+ triggerからDEPRECATED);までがエラー
385
+ 対象の383行目です。

7

内容の修正

2016/09/07 13:02

投稿

sort_merge
sort_merge

スコア16

title CHANGED
File without changes
body CHANGED
@@ -352,4 +352,7 @@
352
352
  ![イメージ説明](e3e8b2140b581b1761d0ee8101163206.png)
353
353
 
354
354
  上の2つのコードを実装してみたあとのエラーの画像(viewに関して)
355
- ![イメージ説明](48b451e9ce99c813796ff938639cc4c2.png)
355
+ ![イメージ説明](48b451e9ce99c813796ff938639cc4c2.png)
356
+
357
+ /posts/view/1にアクセスした際のエラー画像
358
+ ![イメージ説明](79e80441af064052b7f35226d1aaa2ac.png)

6

内容の修正

2016/09/07 09:03

投稿

sort_merge
sort_merge

スコア16

title CHANGED
File without changes
body CHANGED
@@ -343,4 +343,13 @@
343
343
  ![イメージ説明](4a3cb6325a0d1e0637db80afb0bb422b.png)
344
344
 
345
345
  (追加する前のURLに出たエラー)
346
- ![イメージ説明](00ad73ebe4f50672d2ae206765c40fb9.png)
346
+ ![イメージ説明](00ad73ebe4f50672d2ae206765c40fb9.png)
347
+
348
+ CakeBlogController.phpの作成を命じられたエラーの画像
349
+ ![イメージ説明](d532aa16aa2201a177ec40081d2087b1.png)
350
+
351
+ このエラー通りに作成したあとのエラーの画像
352
+ ![イメージ説明](e3e8b2140b581b1761d0ee8101163206.png)
353
+
354
+ 上の2つのコードを実装してみたあとのエラーの画像(viewに関して)
355
+ ![イメージ説明](48b451e9ce99c813796ff938639cc4c2.png)

5

内容の訂正

2016/09/07 08:16

投稿

sort_merge
sort_merge

スコア16

title CHANGED
File without changes
body CHANGED
@@ -336,4 +336,11 @@
336
336
  </li>
337
337
  <?php endforeach; ?>
338
338
  </ul>
339
- ```
339
+ ```
340
+
341
+ これを実装した際に出たエラー画像
342
+ (/cake_blog/posts/view/1を追加した際に出たエラー)
343
+ ![イメージ説明](4a3cb6325a0d1e0637db80afb0bb422b.png)
344
+
345
+ (追加する前のURLに出たエラー)
346
+ ![イメージ説明](00ad73ebe4f50672d2ae206765c40fb9.png)

4

内容の訂正

2016/09/06 13:26

投稿

sort_merge
sort_merge

スコア16

title CHANGED
File without changes
body CHANGED
@@ -68,4 +68,272 @@
68
68
 
69
69
  それで、PostController.phpに表示されたコードを追加したところ、以下のようになりました。
70
70
 
71
- ![イメージ説明](44c22546ee4c6ece8da4d156bc9bec0b.png)
71
+ ![イメージ説明](44c22546ee4c6ece8da4d156bc9bec0b.png)
72
+
73
+ 変更したソースコード
74
+
75
+ PostsController.php
76
+ ```
77
+ <?php
78
+ App::uses('AppController', 'Controller');
79
+ /**
80
+ * Posts Controller
81
+ */
82
+ class PostsController extends AppController {
83
+ /** 8~56行目追加*/
84
+ public $scaffold;
85
+
86
+ public $helper = array('HTML', 'Form');
87
+
88
+ public function index() {
89
+ $this->set('posts', $this->Post->find('all')); //$this->setでPosts変数へ代入。 $this->Post->fin('all')で記事を全て持ってくる。
90
+ }
91
+
92
+ public $helper = array('HTML', 'Form');
93
+
94
+ public function index() {
95
+ $this->set('posts', $this->Post->find('all')); //$this->setでPosts変数へ代入。 $this->Post->fin('all')で記事を全て持ってくる。
96
+ $this->set('title_for_layout', '記事一覧'); //タイトルをセット
97
+ }
98
+
99
+ public $helper = array('HTML', 'Form');
100
+
101
+ public function index() {
102
+ $param = array (
103
+ 'order' => 'modified desc',
104
+ 'limit' => 2
105
+ );
106
+
107
+ $this->set('posts', $this->Post->find('all', $param)); //$this->setでPosts変数へ代入。 $this->Post->fin('all')で記事を全て持ってくる。
108
+ $this->set('title_for_layout', '記事一覧'); //タイトルをセット
109
+ }
110
+
111
+ public $helper = array('HTML', 'Form');
112
+
113
+ public function index() {
114
+ $this->set('posts', $this->Post->find('all')); //$this->setでPosts変数へ代入。 $this->Post->fin('all')で記事を全て持ってくる。
115
+ $this->set('title_for_layout', '記事一覧'); //タイトルをセット
116
+ }
117
+
118
+ public function view($id = null) {
119
+ $this->Post->id = $id;
120
+ $this->set('post', $this->Post->read());
121
+ }
122
+
123
+ public function add() {
124
+ if ($this->request->is('post')) {
125
+ if ($this->Post->save($this->request->data)) {
126
+ $this->Session->setFlash('Success!');
127
+ $this->redirect(array('action' => 'index'));
128
+ } else {
129
+ $this->Session->setFlash('failed');
130
+ }
131
+ }
132
+ }
133
+ /**
134
+ * Scaffold
135
+ *
136
+ * @var mixed
137
+ */
138
+ //public $scaffold;
139
+
140
+ public function index(){
141
+
142
+ $posts = $this->Post->find('all');
143
+ $this->set('posts', $posts);
144
+ }
145
+ public function view() {
146
+
147
+ }
148
+ }
149
+ ?>
150
+ ```
151
+ add.ctp
152
+ ```
153
+ <h2>Add post</h2>
154
+
155
+ <?php
156
+ echo $this->Form->create('Post');
157
+ echo $this->Form->input('title');
158
+ echo $this->Form->input('body', array('rows'=>3));
159
+ echo $this->Form->end('Save Post');
160
+ ```
161
+ index.ctp
162
+ ```
163
+ <?php
164
+
165
+ //print_r($posts);
166
+
167
+ foreach($posts as $post){
168
+ echo $post['Post']['title']."<br>\n";
169
+ echo $post['Post']['body']."<br>\n";
170
+ # code...
171
+ }
172
+ ?>
173
+
174
+ <ul>
175
+ <?php foreach ($posts as $post) : ?>
176
+ <li>
177
+ <?php
178
+ debug($post);
179
+ ?>
180
+ </li>
181
+ <?php endforeach; ?>
182
+ </ul>
183
+
184
+ </address>
185
+ <h2>記事一覧</h2>
186
+
187
+ <ul>
188
+ <?php foreach ($posts as $post) : ?>
189
+ <li>
190
+ <?php
191
+ // debug($post);
192
+ echo h($post['Post']['title']); //hとはCakePHPが持っているHTML Special charactoresの省略形
193
+ ?>
194
+ </li>
195
+ <?php endforeach; ?>
196
+ </ul>
197
+
198
+ <h2>Add Post</h2>
199
+ <?php echo $this->Html->link('Add post', array('controller' => 'posts', 'action' => 'add'));
200
+ ?>
201
+ ```
202
+ routes.php
203
+ ```
204
+ <?php
205
+ /**
206
+ * Routes configuration
207
+ *
208
+ * In this file, you set up routes to your controllers and their actions.
209
+ * Routes are very important mechanism that allows you to freely connect
210
+ * different urls to chosen controllers and their actions (functions).
211
+ *
212
+ * PHP 5
213
+ *
214
+ * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
215
+ * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
216
+ *
217
+ * Licensed under The MIT License
218
+ * For full copyright and license information, please see the LICENSE.txt
219
+ * Redistributions of files must retain the above copyright notice.
220
+ *
221
+ * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
222
+ * @link http://cakephp.org CakePHP(tm) Project
223
+ * @package app.Config
224
+ * @since CakePHP(tm) v 0.2.9
225
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
226
+ */
227
+ /**
228
+ * Here, we are connecting '/' (base path) to controller called 'Pages',
229
+ * its action called 'display', and we pass a param to select the view file
230
+ * to use (in this case, /app/View/Pages/home.ctp)...
231
+ */
232
+ Router::connect('/', array('controller' => 'posts', 'action' => 'index'));/**追加*/
233
+
234
+ Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
235
+ /**
236
+ * ...and connect the rest of 'Pages' controller's urls.
237
+ */
238
+ Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
239
+
240
+ /**
241
+ * Load all plugin routes. See the CakePlugin documentation on
242
+ * how to customize the loading of plugin routes.
243
+ */
244
+ CakePlugin::routes();
245
+
246
+ /**
247
+ * Load the CakePHP default routes. Only remove this if you do not want to use
248
+ * the built-in default routes.
249
+ */
250
+ require CAKE . 'Config' . DS . 'routes.php';
251
+ ```
252
+ default.ctp
253
+ ```
254
+ <?php
255
+ /**
256
+ *
257
+ * PHP 5
258
+ *
259
+ * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
260
+ * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
261
+ *
262
+ * Licensed under The MIT License
263
+ * For full copyright and license information, please see the LICENSE.txt
264
+ * Redistributions of files must retain the above copyright notice.
265
+ *
266
+ * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
267
+ * @link http://cakephp.org CakePHP(tm) Project
268
+ * @package app.View.Layouts
269
+ * @since CakePHP(tm) v 0.10.0.1076
270
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
271
+ */
272
+ <title>
273
+ <?php echo $title_for_layout; ?>
274
+ </title>
275
+
276
+ <div id="header">
277
+ <h1><?php echo $this->Html->link('Home', '/'); ?></h1>
278
+ </div>
279
+ $cakeDescription = __d('cake_dev', 'CakePHP: the rapid development php framework');
280
+ ?>
281
+ <!DOCTYPE html>
282
+ <html>
283
+ <head>
284
+ <?php echo $this->Html->charset(); ?>
285
+ <title>
286
+ <?php echo $cakeDescription ?>:
287
+ <?php echo $title_for_layout; ?>
288
+ </title>
289
+ <?php
290
+ echo $this->Html->meta('icon');
291
+
292
+ echo $this->Html->css('cake.generic');
293
+
294
+ echo $this->fetch('meta');
295
+ echo $this->fetch('css');
296
+ echo $this->fetch('script');
297
+ ?>
298
+ </head>
299
+ <body>
300
+ <div id="container">
301
+ <div id="header">
302
+ <h1><?php echo $this->Html->link($cakeDescription, 'http://cakephp.org'); ?></h1>
303
+ </div>
304
+ <div id="content">
305
+
306
+ <?php echo $this->Session->flash(); ?>
307
+
308
+ <?php echo $this->fetch('content'); ?>
309
+ </div>
310
+ <div id="footer">
311
+ <?php echo $this->Html->link(
312
+ $this->Html->image('cake.power.gif', array('alt' => $cakeDescription, 'border' => '0')),
313
+ 'http://www.cakephp.org/',
314
+ array('target' => '_blank', 'escape' => false)
315
+ );
316
+ ?>
317
+ </div>
318
+ </div>
319
+ <?php echo $this->element('sql_dump'); ?>
320
+ </body>
321
+ </html>
322
+
323
+ ```
324
+ view.ctp
325
+ ```ここに言語を入力
326
+ <h2><?php echo h($post['Post']['title']); ?></h2>
327
+ <p><?php echo h($post['Post']['body']); ?></p>
328
+
329
+ <h2>Comments</h2>
330
+ <ul>
331
+ <?php foreach ($post['Comments'] as $comment) : ?>
332
+ <li>
333
+ <?php
334
+ echo h($comment['body']);
335
+ ?>
336
+ </li>
337
+ <?php endforeach; ?>
338
+ </ul>
339
+ ```

3

内容の訂正

2016/09/06 13:21

投稿

sort_merge
sort_merge

スコア16

title CHANGED
File without changes
body CHANGED
@@ -59,4 +59,13 @@
59
59
 
60
60
  /cake_blog/posts/view/1にアクセスした結果
61
61
 
62
- ![イメージ説明](a2aec0c35deea646d206577559761d2c.png)
62
+ ![イメージ説明](a2aec0c35deea646d206577559761d2c.png)
63
+
64
+ /cake_blog/posts/view/1を追加し、アクセスしたところ、以下のようなエラーが出ました。
65
+
66
+ ![イメージ説明](d605dec5ca520714134ee4a07da813f6.png)
67
+
68
+
69
+ それで、PostController.phpに表示されたコードを追加したところ、以下のようになりました。
70
+
71
+ ![イメージ説明](44c22546ee4c6ece8da4d156bc9bec0b.png)

2

内容の訂正

2016/09/06 10:43

投稿

sort_merge
sort_merge

スコア16

title CHANGED
File without changes
body CHANGED
@@ -55,4 +55,8 @@
55
55
  ![イメージ説明](ec393641c6ad90b61d3e21fb4affaea5.png)
56
56
 
57
57
  追加後
58
- ![イメージ説明](bbe4d513c0cea7439bede34bf41b524b.png)
58
+ ![イメージ説明](bbe4d513c0cea7439bede34bf41b524b.png)
59
+
60
+ /cake_blog/posts/view/1にアクセスした結果
61
+
62
+ ![イメージ説明](a2aec0c35deea646d206577559761d2c.png)

1

内容の訂正

2016/09/06 09:32

投稿

sort_merge
sort_merge

スコア16

title CHANGED
File without changes
body CHANGED
@@ -46,4 +46,13 @@
46
46
 
47
47
  参考にしているサイトのように表示させるにはどうしたらよいか教えていただきたいです。
48
48
 
49
- どうかよろしくお願いします。
49
+ どうかよろしくお願いします。
50
+
51
+ ※追加
52
+ icchiさん、kunaiさんに言われた通りDBにID3、4、9のデータを追加したところ、SQLの方に変化はありましたが、表示されませんでした。
53
+
54
+ DBへの追加
55
+ ![イメージ説明](ec393641c6ad90b61d3e21fb4affaea5.png)
56
+
57
+ 追加後
58
+ ![イメージ説明](bbe4d513c0cea7439bede34bf41b524b.png)