From ebbd81771519a1923dd167dbad8c829cf1794daf Mon Sep 17 00:00:00 2001 From: Jonathon Menz Date: Mon, 2 Jul 2018 16:48:15 -0700 Subject: [PATCH] Fix: Set failover object --- src/CustomErrorControllerExtension.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/CustomErrorControllerExtension.php b/src/CustomErrorControllerExtension.php index 782cc76..e5c9698 100755 --- a/src/CustomErrorControllerExtension.php +++ b/src/CustomErrorControllerExtension.php @@ -81,7 +81,13 @@ public function customError($errorCode, $customFields, $template = null, $contro $defaultCustomFields, $customFields ); - $body = $controllerType::create()->renderWith($template, $customFields); + // Remove 'Controller' from class name to get related Page type + $pageType = substr_replace($controllerType, '', strrpos($controllerType, 'Controller'), strlen('Controller')); + // Create a dummy page to act as a failover for the controller + $dataRecord = $pageType::create(); + $dataRecord->ID = -1; + // Set the response body + $body = $controllerType::create($dataRecord)->renderWith($template, $customFields); $response->setBody($body); if ($response) { throw new HTTPResponse_Exception($response, $errorCode);