From c17e3f0e04b73cd1df9e1a72b1caba280c5049df Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Sun, 21 Mar 2010 00:21:04 +0000 Subject: [PATCH] Improved template handling with exceptions The Page class is now responsible for executing the subpage template rather than the index file. Template processing has been improved with exceptions to catch 404s, or any other template exception, which will abort the current page and display an error document instead. --- pages/errors/404.php | 9 ++++++ pages/errors/unhandled-exception.php | 10 +++++++ templates/errors/404.tpl | 6 ++++ templates/errors/unhandled-exception.tpl | 36 ++++++++++++++++++++++++ 4 files changed, 61 insertions(+) create mode 100644 pages/errors/404.php create mode 100644 pages/errors/unhandled-exception.php create mode 100644 templates/errors/404.tpl create mode 100644 templates/errors/unhandled-exception.tpl diff --git a/pages/errors/404.php b/pages/errors/404.php new file mode 100644 index 0000000..d5bc834 --- /dev/null +++ b/pages/errors/404.php @@ -0,0 +1,9 @@ +request(); + +$this->smarty->assign('requested_page', htmlspecialchars($req->request_string())); + + +?> \ No newline at end of file diff --git a/pages/errors/unhandled-exception.php b/pages/errors/unhandled-exception.php new file mode 100644 index 0000000..1427536 --- /dev/null +++ b/pages/errors/unhandled-exception.php @@ -0,0 +1,10 @@ +config(); + +$this->smarty->assign('display_exceptions', $config->get('debug.display_exceptions')); +$this->smarty->assign('exception', $exception); +$this->smarty->assign('exception_type', get_class($exception)); + +?> \ No newline at end of file diff --git a/templates/errors/404.tpl b/templates/errors/404.tpl new file mode 100644 index 0000000..607707a --- /dev/null +++ b/templates/errors/404.tpl @@ -0,0 +1,6 @@ +

The requested page could not be found

+

+ The file you requested ({$requested_page}) could not be found. + If you typed in the address manually, check that you have spelled it correctly, + or if you followed a link, let us know and we'll look into it. +

\ No newline at end of file diff --git a/templates/errors/unhandled-exception.tpl b/templates/errors/unhandled-exception.tpl new file mode 100644 index 0000000..f1e02c9 --- /dev/null +++ b/templates/errors/unhandled-exception.tpl @@ -0,0 +1,36 @@ +

An unhandled error has occurred

+

+ There was a problem trying to complete the requested action. Please try again and if the problem persists, let us know. +

+ +{if $display_exceptions} +

+ An unhandled exception was caught during the page template processing. The full details are shown below: +

+ + + + + + + + + + + + + + + + + + + + + + + + + +
Exception{$exception_type}
File{$exception->getFile()}
Line{$exception->getLine()}
Message{$exception->getMessage()}
+{/if} \ No newline at end of file