質問編集履歴
8
内容の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -713,3 +713,57 @@
|
|
713
713
|
/posts/view/1にアクセスした際のエラー画像
|
714
714
|
|
715
715
|

|
716
|
+
|
717
|
+
|
718
|
+
|
719
|
+
icchiさん修正前のview.ctpを実装した際のブラウザの画像(エラー含む)
|
720
|
+
|
721
|
+
|
722
|
+
|
723
|
+
説明](a0c676fb952eb45baa39e5bec69271db.png)](7eef62bc967560326603bd36e95c7442.png)
|
724
|
+
|
725
|
+
|
726
|
+
|
727
|
+
icchiさん修正後のview.ctpを実装した際のブラウザ
|
728
|
+
|
729
|
+
の画像(エラー含む)
|
730
|
+
|
731
|
+
|
732
|
+
|
733
|
+

|
734
|
+
|
735
|
+
|
736
|
+
|
737
|
+
修正前と修正後両方を足したview.ctpを実装した際のブラウザ
|
738
|
+
|
739
|
+
の画像(エラー含む)
|
740
|
+
|
741
|
+
|
742
|
+
|
743
|
+

|
744
|
+
|
745
|
+
|
746
|
+
|
747
|
+
修正前の実装で出たエラーFormHelper.phpのコードを載せようとしたところ、字数オーバーになってしまったので、エラーに関する行を載せさせていただきます。
|
748
|
+
|
749
|
+
その行だけではわからないという場合は教えてください。
|
750
|
+
|
751
|
+
|
752
|
+
|
753
|
+
FormHelper.phpのエラーに関するソースコード
|
754
|
+
|
755
|
+
```
|
756
|
+
|
757
|
+
if (isset($options['action'])) {
|
758
|
+
|
759
|
+
trigger_error('Using key `action` is deprecated, use `url` directly instead.', E_USER_DEPRECATED);
|
760
|
+
|
761
|
+
}
|
762
|
+
|
763
|
+
```
|
764
|
+
|
765
|
+
|
766
|
+
|
767
|
+
triggerからDEPRECATED);までがエラー
|
768
|
+
|
769
|
+
対象の383行目です。
|
7
内容の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -707,3 +707,9 @@
|
|
707
707
|
上の2つのコードを実装してみたあとのエラーの画像(viewに関して)
|
708
708
|
|
709
709
|

|
710
|
+
|
711
|
+
|
712
|
+
|
713
|
+
/posts/view/1にアクセスした際のエラー画像
|
714
|
+
|
715
|
+

|
6
内容の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -689,3 +689,21 @@
|
|
689
689
|
(追加する前のURLに出たエラー)
|
690
690
|
|
691
691
|

|
692
|
+
|
693
|
+
|
694
|
+
|
695
|
+
CakeBlogController.phpの作成を命じられたエラーの画像
|
696
|
+
|
697
|
+

|
698
|
+
|
699
|
+
|
700
|
+
|
701
|
+
このエラー通りに作成したあとのエラーの画像
|
702
|
+
|
703
|
+

|
704
|
+
|
705
|
+
|
706
|
+
|
707
|
+
上の2つのコードを実装してみたあとのエラーの画像(viewに関して)
|
708
|
+
|
709
|
+

|
5
内容の訂正
test
CHANGED
File without changes
|
test
CHANGED
@@ -675,3 +675,17 @@
|
|
675
675
|
</ul>
|
676
676
|
|
677
677
|
```
|
678
|
+
|
679
|
+
|
680
|
+
|
681
|
+
これを実装した際に出たエラー画像
|
682
|
+
|
683
|
+
(/cake_blog/posts/view/1を追加した際に出たエラー)
|
684
|
+
|
685
|
+

|
686
|
+
|
687
|
+
|
688
|
+
|
689
|
+
(追加する前のURLに出たエラー)
|
690
|
+
|
691
|
+

|
4
内容の訂正
test
CHANGED
File without changes
|
test
CHANGED
@@ -139,3 +139,539 @@
|
|
139
139
|
|
140
140
|
|
141
141
|

|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
変更したソースコード
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
PostsController.php
|
150
|
+
|
151
|
+
```
|
152
|
+
|
153
|
+
<?php
|
154
|
+
|
155
|
+
App::uses('AppController', 'Controller');
|
156
|
+
|
157
|
+
/**
|
158
|
+
|
159
|
+
* Posts Controller
|
160
|
+
|
161
|
+
*/
|
162
|
+
|
163
|
+
class PostsController extends AppController {
|
164
|
+
|
165
|
+
/** 8~56行目追加*/
|
166
|
+
|
167
|
+
public $scaffold;
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
public $helper = array('HTML', 'Form');
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
public function index() {
|
176
|
+
|
177
|
+
$this->set('posts', $this->Post->find('all')); //$this->setでPosts変数へ代入。 $this->Post->fin('all')で記事を全て持ってくる。
|
178
|
+
|
179
|
+
}
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
public $helper = array('HTML', 'Form');
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
public function index() {
|
188
|
+
|
189
|
+
$this->set('posts', $this->Post->find('all')); //$this->setでPosts変数へ代入。 $this->Post->fin('all')で記事を全て持ってくる。
|
190
|
+
|
191
|
+
$this->set('title_for_layout', '記事一覧'); //タイトルをセット
|
192
|
+
|
193
|
+
}
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
public $helper = array('HTML', 'Form');
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
public function index() {
|
202
|
+
|
203
|
+
$param = array (
|
204
|
+
|
205
|
+
'order' => 'modified desc',
|
206
|
+
|
207
|
+
'limit' => 2
|
208
|
+
|
209
|
+
);
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
$this->set('posts', $this->Post->find('all', $param)); //$this->setでPosts変数へ代入。 $this->Post->fin('all')で記事を全て持ってくる。
|
214
|
+
|
215
|
+
$this->set('title_for_layout', '記事一覧'); //タイトルをセット
|
216
|
+
|
217
|
+
}
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
public $helper = array('HTML', 'Form');
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
public function index() {
|
226
|
+
|
227
|
+
$this->set('posts', $this->Post->find('all')); //$this->setでPosts変数へ代入。 $this->Post->fin('all')で記事を全て持ってくる。
|
228
|
+
|
229
|
+
$this->set('title_for_layout', '記事一覧'); //タイトルをセット
|
230
|
+
|
231
|
+
}
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
public function view($id = null) {
|
236
|
+
|
237
|
+
$this->Post->id = $id;
|
238
|
+
|
239
|
+
$this->set('post', $this->Post->read());
|
240
|
+
|
241
|
+
}
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
public function add() {
|
246
|
+
|
247
|
+
if ($this->request->is('post')) {
|
248
|
+
|
249
|
+
if ($this->Post->save($this->request->data)) {
|
250
|
+
|
251
|
+
$this->Session->setFlash('Success!');
|
252
|
+
|
253
|
+
$this->redirect(array('action' => 'index'));
|
254
|
+
|
255
|
+
} else {
|
256
|
+
|
257
|
+
$this->Session->setFlash('failed');
|
258
|
+
|
259
|
+
}
|
260
|
+
|
261
|
+
}
|
262
|
+
|
263
|
+
}
|
264
|
+
|
265
|
+
/**
|
266
|
+
|
267
|
+
* Scaffold
|
268
|
+
|
269
|
+
*
|
270
|
+
|
271
|
+
* @var mixed
|
272
|
+
|
273
|
+
*/
|
274
|
+
|
275
|
+
//public $scaffold;
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
public function index(){
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
$posts = $this->Post->find('all');
|
284
|
+
|
285
|
+
$this->set('posts', $posts);
|
286
|
+
|
287
|
+
}
|
288
|
+
|
289
|
+
public function view() {
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
}
|
294
|
+
|
295
|
+
}
|
296
|
+
|
297
|
+
?>
|
298
|
+
|
299
|
+
```
|
300
|
+
|
301
|
+
add.ctp
|
302
|
+
|
303
|
+
```
|
304
|
+
|
305
|
+
<h2>Add post</h2>
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
<?php
|
310
|
+
|
311
|
+
echo $this->Form->create('Post');
|
312
|
+
|
313
|
+
echo $this->Form->input('title');
|
314
|
+
|
315
|
+
echo $this->Form->input('body', array('rows'=>3));
|
316
|
+
|
317
|
+
echo $this->Form->end('Save Post');
|
318
|
+
|
319
|
+
```
|
320
|
+
|
321
|
+
index.ctp
|
322
|
+
|
323
|
+
```
|
324
|
+
|
325
|
+
<?php
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
//print_r($posts);
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
foreach($posts as $post){
|
334
|
+
|
335
|
+
echo $post['Post']['title']."<br>\n";
|
336
|
+
|
337
|
+
echo $post['Post']['body']."<br>\n";
|
338
|
+
|
339
|
+
# code...
|
340
|
+
|
341
|
+
}
|
342
|
+
|
343
|
+
?>
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
<ul>
|
348
|
+
|
349
|
+
<?php foreach ($posts as $post) : ?>
|
350
|
+
|
351
|
+
<li>
|
352
|
+
|
353
|
+
<?php
|
354
|
+
|
355
|
+
debug($post);
|
356
|
+
|
357
|
+
?>
|
358
|
+
|
359
|
+
</li>
|
360
|
+
|
361
|
+
<?php endforeach; ?>
|
362
|
+
|
363
|
+
</ul>
|
364
|
+
|
365
|
+
|
366
|
+
|
367
|
+
</address>
|
368
|
+
|
369
|
+
<h2>記事一覧</h2>
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
<ul>
|
374
|
+
|
375
|
+
<?php foreach ($posts as $post) : ?>
|
376
|
+
|
377
|
+
<li>
|
378
|
+
|
379
|
+
<?php
|
380
|
+
|
381
|
+
// debug($post);
|
382
|
+
|
383
|
+
echo h($post['Post']['title']); //hとはCakePHPが持っているHTML Special charactoresの省略形
|
384
|
+
|
385
|
+
?>
|
386
|
+
|
387
|
+
</li>
|
388
|
+
|
389
|
+
<?php endforeach; ?>
|
390
|
+
|
391
|
+
</ul>
|
392
|
+
|
393
|
+
|
394
|
+
|
395
|
+
<h2>Add Post</h2>
|
396
|
+
|
397
|
+
<?php echo $this->Html->link('Add post', array('controller' => 'posts', 'action' => 'add'));
|
398
|
+
|
399
|
+
?>
|
400
|
+
|
401
|
+
```
|
402
|
+
|
403
|
+
routes.php
|
404
|
+
|
405
|
+
```
|
406
|
+
|
407
|
+
<?php
|
408
|
+
|
409
|
+
/**
|
410
|
+
|
411
|
+
* Routes configuration
|
412
|
+
|
413
|
+
*
|
414
|
+
|
415
|
+
* In this file, you set up routes to your controllers and their actions.
|
416
|
+
|
417
|
+
* Routes are very important mechanism that allows you to freely connect
|
418
|
+
|
419
|
+
* different urls to chosen controllers and their actions (functions).
|
420
|
+
|
421
|
+
*
|
422
|
+
|
423
|
+
* PHP 5
|
424
|
+
|
425
|
+
*
|
426
|
+
|
427
|
+
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
428
|
+
|
429
|
+
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
430
|
+
|
431
|
+
*
|
432
|
+
|
433
|
+
* Licensed under The MIT License
|
434
|
+
|
435
|
+
* For full copyright and license information, please see the LICENSE.txt
|
436
|
+
|
437
|
+
* Redistributions of files must retain the above copyright notice.
|
438
|
+
|
439
|
+
*
|
440
|
+
|
441
|
+
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
442
|
+
|
443
|
+
* @link http://cakephp.org CakePHP(tm) Project
|
444
|
+
|
445
|
+
* @package app.Config
|
446
|
+
|
447
|
+
* @since CakePHP(tm) v 0.2.9
|
448
|
+
|
449
|
+
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
450
|
+
|
451
|
+
*/
|
452
|
+
|
453
|
+
/**
|
454
|
+
|
455
|
+
* Here, we are connecting '/' (base path) to controller called 'Pages',
|
456
|
+
|
457
|
+
* its action called 'display', and we pass a param to select the view file
|
458
|
+
|
459
|
+
* to use (in this case, /app/View/Pages/home.ctp)...
|
460
|
+
|
461
|
+
*/
|
462
|
+
|
463
|
+
Router::connect('/', array('controller' => 'posts', 'action' => 'index'));/**追加*/
|
464
|
+
|
465
|
+
|
466
|
+
|
467
|
+
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
|
468
|
+
|
469
|
+
/**
|
470
|
+
|
471
|
+
* ...and connect the rest of 'Pages' controller's urls.
|
472
|
+
|
473
|
+
*/
|
474
|
+
|
475
|
+
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
|
476
|
+
|
477
|
+
|
478
|
+
|
479
|
+
/**
|
480
|
+
|
481
|
+
* Load all plugin routes. See the CakePlugin documentation on
|
482
|
+
|
483
|
+
* how to customize the loading of plugin routes.
|
484
|
+
|
485
|
+
*/
|
486
|
+
|
487
|
+
CakePlugin::routes();
|
488
|
+
|
489
|
+
|
490
|
+
|
491
|
+
/**
|
492
|
+
|
493
|
+
* Load the CakePHP default routes. Only remove this if you do not want to use
|
494
|
+
|
495
|
+
* the built-in default routes.
|
496
|
+
|
497
|
+
*/
|
498
|
+
|
499
|
+
require CAKE . 'Config' . DS . 'routes.php';
|
500
|
+
|
501
|
+
```
|
502
|
+
|
503
|
+
default.ctp
|
504
|
+
|
505
|
+
```
|
506
|
+
|
507
|
+
<?php
|
508
|
+
|
509
|
+
/**
|
510
|
+
|
511
|
+
*
|
512
|
+
|
513
|
+
* PHP 5
|
514
|
+
|
515
|
+
*
|
516
|
+
|
517
|
+
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
518
|
+
|
519
|
+
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
520
|
+
|
521
|
+
*
|
522
|
+
|
523
|
+
* Licensed under The MIT License
|
524
|
+
|
525
|
+
* For full copyright and license information, please see the LICENSE.txt
|
526
|
+
|
527
|
+
* Redistributions of files must retain the above copyright notice.
|
528
|
+
|
529
|
+
*
|
530
|
+
|
531
|
+
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
532
|
+
|
533
|
+
* @link http://cakephp.org CakePHP(tm) Project
|
534
|
+
|
535
|
+
* @package app.View.Layouts
|
536
|
+
|
537
|
+
* @since CakePHP(tm) v 0.10.0.1076
|
538
|
+
|
539
|
+
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
540
|
+
|
541
|
+
*/
|
542
|
+
|
543
|
+
<title>
|
544
|
+
|
545
|
+
<?php echo $title_for_layout; ?>
|
546
|
+
|
547
|
+
</title>
|
548
|
+
|
549
|
+
|
550
|
+
|
551
|
+
<div id="header">
|
552
|
+
|
553
|
+
<h1><?php echo $this->Html->link('Home', '/'); ?></h1>
|
554
|
+
|
555
|
+
</div>
|
556
|
+
|
557
|
+
$cakeDescription = __d('cake_dev', 'CakePHP: the rapid development php framework');
|
558
|
+
|
559
|
+
?>
|
560
|
+
|
561
|
+
<!DOCTYPE html>
|
562
|
+
|
563
|
+
<html>
|
564
|
+
|
565
|
+
<head>
|
566
|
+
|
567
|
+
<?php echo $this->Html->charset(); ?>
|
568
|
+
|
569
|
+
<title>
|
570
|
+
|
571
|
+
<?php echo $cakeDescription ?>:
|
572
|
+
|
573
|
+
<?php echo $title_for_layout; ?>
|
574
|
+
|
575
|
+
</title>
|
576
|
+
|
577
|
+
<?php
|
578
|
+
|
579
|
+
echo $this->Html->meta('icon');
|
580
|
+
|
581
|
+
|
582
|
+
|
583
|
+
echo $this->Html->css('cake.generic');
|
584
|
+
|
585
|
+
|
586
|
+
|
587
|
+
echo $this->fetch('meta');
|
588
|
+
|
589
|
+
echo $this->fetch('css');
|
590
|
+
|
591
|
+
echo $this->fetch('script');
|
592
|
+
|
593
|
+
?>
|
594
|
+
|
595
|
+
</head>
|
596
|
+
|
597
|
+
<body>
|
598
|
+
|
599
|
+
<div id="container">
|
600
|
+
|
601
|
+
<div id="header">
|
602
|
+
|
603
|
+
<h1><?php echo $this->Html->link($cakeDescription, 'http://cakephp.org'); ?></h1>
|
604
|
+
|
605
|
+
</div>
|
606
|
+
|
607
|
+
<div id="content">
|
608
|
+
|
609
|
+
|
610
|
+
|
611
|
+
<?php echo $this->Session->flash(); ?>
|
612
|
+
|
613
|
+
|
614
|
+
|
615
|
+
<?php echo $this->fetch('content'); ?>
|
616
|
+
|
617
|
+
</div>
|
618
|
+
|
619
|
+
<div id="footer">
|
620
|
+
|
621
|
+
<?php echo $this->Html->link(
|
622
|
+
|
623
|
+
$this->Html->image('cake.power.gif', array('alt' => $cakeDescription, 'border' => '0')),
|
624
|
+
|
625
|
+
'http://www.cakephp.org/',
|
626
|
+
|
627
|
+
array('target' => '_blank', 'escape' => false)
|
628
|
+
|
629
|
+
);
|
630
|
+
|
631
|
+
?>
|
632
|
+
|
633
|
+
</div>
|
634
|
+
|
635
|
+
</div>
|
636
|
+
|
637
|
+
<?php echo $this->element('sql_dump'); ?>
|
638
|
+
|
639
|
+
</body>
|
640
|
+
|
641
|
+
</html>
|
642
|
+
|
643
|
+
|
644
|
+
|
645
|
+
```
|
646
|
+
|
647
|
+
view.ctp
|
648
|
+
|
649
|
+
```ここに言語を入力
|
650
|
+
|
651
|
+
<h2><?php echo h($post['Post']['title']); ?></h2>
|
652
|
+
|
653
|
+
<p><?php echo h($post['Post']['body']); ?></p>
|
654
|
+
|
655
|
+
|
656
|
+
|
657
|
+
<h2>Comments</h2>
|
658
|
+
|
659
|
+
<ul>
|
660
|
+
|
661
|
+
<?php foreach ($post['Comments'] as $comment) : ?>
|
662
|
+
|
663
|
+
<li>
|
664
|
+
|
665
|
+
<?php
|
666
|
+
|
667
|
+
echo h($comment['body']);
|
668
|
+
|
669
|
+
?>
|
670
|
+
|
671
|
+
</li>
|
672
|
+
|
673
|
+
<?php endforeach; ?>
|
674
|
+
|
675
|
+
</ul>
|
676
|
+
|
677
|
+
```
|
3
内容の訂正
test
CHANGED
File without changes
|
test
CHANGED
@@ -121,3 +121,21 @@
|
|
121
121
|
|
122
122
|
|
123
123
|

|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
/cake_blog/posts/view/1を追加し、アクセスしたところ、以下のようなエラーが出ました。
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+

|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
それで、PostController.phpに表示されたコードを追加したところ、以下のようになりました。
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+

|
2
内容の訂正
test
CHANGED
File without changes
|
test
CHANGED
@@ -113,3 +113,11 @@
|
|
113
113
|
追加後
|
114
114
|
|
115
115
|

|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
/cake_blog/posts/view/1にアクセスした結果
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+

|
1
内容の訂正
test
CHANGED
File without changes
|
test
CHANGED
@@ -95,3 +95,21 @@
|
|
95
95
|
|
96
96
|
|
97
97
|
どうかよろしくお願いします。
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
※追加
|
102
|
+
|
103
|
+
icchiさん、kunaiさんに言われた通りDBにID3、4、9のデータを追加したところ、SQLの方に変化はありましたが、表示されませんでした。
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
DBへの追加
|
108
|
+
|
109
|
+

|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
追加後
|
114
|
+
|
115
|
+

|