File tree Expand file tree Collapse file tree 4 files changed +59
-3
lines changed
Console/Templates/skel/Controller Expand file tree Collapse file tree 4 files changed +59
-3
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,8 @@ class PagesController extends AppController {
50
50
*
51
51
* @param mixed What page to display
52
52
* @return void
53
+ * @throws NotFoundException When the view file could not be found
54
+ * or MissingViewException in debug mode.
53
55
*/
54
56
public function display () {
55
57
$ path = func_get_args ();
@@ -70,6 +72,14 @@ public function display() {
70
72
$ title_for_layout = Inflector::humanize ($ path [$ count - 1 ]);
71
73
}
72
74
$ this ->set (compact ('page ' , 'subpage ' , 'title_for_layout ' ));
73
- $ this ->render (implode ('/ ' , $ path ));
75
+
76
+ try {
77
+ $ this ->render (implode ('/ ' , $ path ));
78
+ } catch (MissingViewException $ e ) {
79
+ if (Configure::read ('debug ' )) {
80
+ throw $ e ;
81
+ }
82
+ throw new NotFoundException ();
83
+ }
74
84
}
75
85
}
Original file line number Diff line number Diff line change @@ -42,6 +42,8 @@ class PagesController extends AppController {
42
42
*
43
43
* @param mixed What page to display
44
44
* @return void
45
+ * @throws NotFoundException When the view file could not be found
46
+ * or MissingViewException in debug mode.
45
47
*/
46
48
public function display () {
47
49
$ path = func_get_args ();
@@ -62,6 +64,14 @@ public function display() {
62
64
$ title_for_layout = Inflector::humanize ($ path [$ count - 1 ]);
63
65
}
64
66
$ this ->set (compact ('page ' , 'subpage ' , 'title_for_layout ' ));
65
- $ this ->render (implode ('/ ' , $ path ));
67
+
68
+ try {
69
+ $ this ->render (implode ('/ ' , $ path ));
70
+ } catch (MissingViewException $ e ) {
71
+ if (Configure::read ('debug ' )) {
72
+ throw $ e ;
73
+ }
74
+ throw new NotFoundException ();
75
+ }
66
76
}
67
77
}
Original file line number Diff line number Diff line change @@ -51,4 +51,30 @@ public function testDisplay() {
51
51
$ this ->assertEquals ('TestTheme ' , $ Pages ->viewVars ['page ' ]);
52
52
$ this ->assertEquals ('Posts ' , $ Pages ->viewVars ['subpage ' ]);
53
53
}
54
+
55
+ /**
56
+ * Test that missing view renders 404 page in production
57
+ *
58
+ * @expectedException NotFoundException
59
+ * @expectedExceptionCode 404
60
+ * @return void
61
+ */
62
+ public function testMissingView () {
63
+ Configure::write ('debug ' , 0 );
64
+ $ Pages = new PagesController (new CakeRequest (null , false ), new CakeResponse ());
65
+ $ Pages ->display ('non_existing_page ' );
66
+ }
67
+
68
+ /**
69
+ * Test that missing view in debug mode renders missing_view error page
70
+ *
71
+ * @expectedException MissingViewException
72
+ * @expectedExceptionCode 500
73
+ * @return void
74
+ */
75
+ public function testMissingViewInDebug () {
76
+ Configure::write ('debug ' , 1 );
77
+ $ Pages = new PagesController (new CakeRequest (null , false ), new CakeResponse ());
78
+ $ Pages ->display ('non_existing_page ' );
79
+ }
54
80
}
Original file line number Diff line number Diff line change @@ -51,6 +51,8 @@ class PagesController extends AppController {
51
51
*
52
52
* @param mixed What page to display
53
53
* @return void
54
+ * @throws NotFoundException When the view file could not be found
55
+ * or MissingViewException in debug mode.
54
56
*/
55
57
public function display () {
56
58
$ path = func_get_args ();
@@ -75,7 +77,15 @@ public function display() {
75
77
'subpage ' => $ subpage ,
76
78
'title_for_layout ' => $ titleForLayout
77
79
));
78
- $ this ->render (implode ('/ ' , $ path ));
80
+
81
+ try {
82
+ $ this ->render (implode ('/ ' , $ path ));
83
+ } catch (MissingViewException $ e ) {
84
+ if (Configure::read ('debug ' )) {
85
+ throw $ e ;
86
+ }
87
+ throw new NotFoundException ();
88
+ }
79
89
}
80
90
81
91
}
You can’t perform that action at this time.
0 commit comments