mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Pages controller should render 404 on missing view file
This commit is contained in:
parent
d992d3a626
commit
1ce9fc537f
4 changed files with 59 additions and 3 deletions
|
@ -50,6 +50,8 @@ class PagesController extends AppController {
|
|||
*
|
||||
* @param mixed What page to display
|
||||
* @return void
|
||||
* @throws NotFoundException When the view file could not be found
|
||||
* or MissingViewException in debug mode.
|
||||
*/
|
||||
public function display() {
|
||||
$path = func_get_args();
|
||||
|
@ -70,6 +72,14 @@ class PagesController extends AppController {
|
|||
$title_for_layout = Inflector::humanize($path[$count - 1]);
|
||||
}
|
||||
$this->set(compact('page', 'subpage', 'title_for_layout'));
|
||||
|
||||
try {
|
||||
$this->render(implode('/', $path));
|
||||
} catch (MissingViewException $e) {
|
||||
if (Configure::read('debug')) {
|
||||
throw $e;
|
||||
}
|
||||
throw new NotFoundException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,6 +42,8 @@ class PagesController extends AppController {
|
|||
*
|
||||
* @param mixed What page to display
|
||||
* @return void
|
||||
* @throws NotFoundException When the view file could not be found
|
||||
* or MissingViewException in debug mode.
|
||||
*/
|
||||
public function display() {
|
||||
$path = func_get_args();
|
||||
|
@ -62,6 +64,14 @@ class PagesController extends AppController {
|
|||
$title_for_layout = Inflector::humanize($path[$count - 1]);
|
||||
}
|
||||
$this->set(compact('page', 'subpage', 'title_for_layout'));
|
||||
|
||||
try {
|
||||
$this->render(implode('/', $path));
|
||||
} catch (MissingViewException $e) {
|
||||
if (Configure::read('debug')) {
|
||||
throw $e;
|
||||
}
|
||||
throw new NotFoundException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,4 +51,30 @@ class PagesControllerTest extends CakeTestCase {
|
|||
$this->assertEquals('TestTheme', $Pages->viewVars['page']);
|
||||
$this->assertEquals('Posts', $Pages->viewVars['subpage']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that missing view renders 404 page in production
|
||||
*
|
||||
* @expectedException NotFoundException
|
||||
* @expectedExceptionCode 404
|
||||
* @return void
|
||||
*/
|
||||
public function testMissingView() {
|
||||
Configure::write('debug', 0);
|
||||
$Pages = new PagesController(new CakeRequest(null, false), new CakeResponse());
|
||||
$Pages->display('non_existing_page');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that missing view in debug mode renders missing_view error page
|
||||
*
|
||||
* @expectedException MissingViewException
|
||||
* @expectedExceptionCode 500
|
||||
* @return void
|
||||
*/
|
||||
public function testMissingViewInDebug() {
|
||||
Configure::write('debug', 1);
|
||||
$Pages = new PagesController(new CakeRequest(null, false), new CakeResponse());
|
||||
$Pages->display('non_existing_page');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,6 +51,8 @@ class PagesController extends AppController {
|
|||
*
|
||||
* @param mixed What page to display
|
||||
* @return void
|
||||
* @throws NotFoundException When the view file could not be found
|
||||
* or MissingViewException in debug mode.
|
||||
*/
|
||||
public function display() {
|
||||
$path = func_get_args();
|
||||
|
@ -75,7 +77,15 @@ class PagesController extends AppController {
|
|||
'subpage' => $subpage,
|
||||
'title_for_layout' => $titleForLayout
|
||||
));
|
||||
|
||||
try {
|
||||
$this->render(implode('/', $path));
|
||||
} catch (MissingViewException $e) {
|
||||
if (Configure::read('debug')) {
|
||||
throw $e;
|
||||
}
|
||||
throw new NotFoundException();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue