Answer the question
In order to leave comments, you need to log in
Exceptions in PHP or how to pass an object to an included file?
How to pass $e to included file?
If: "Exception objects are exceptions only in the catch block and do not propagate to nested files."
The code:
catch (Exception $e)
{
if ($config->phalcon->debug)
{
include_once(rtrim($config->phalcon->viewsDir, '/').'/error/exception_debug.phtml');
}
else
{
include_once(rtrim($config->phalcon->viewsDir, '/').'/error/exception.phtml');
}
}
Answer the question
In order to leave comments, you need to log in
Write a f-th that renders a template and bandits data into it. For example like this:
function render($template, array $data = []) {
if (!file_exists($template)) {
throw Exception("Template {$template} not found");
}
foreach($data as $key => $value) {
$$key = $value;
}
ob_start();
include $template;
return ob_get_clean();
}
catch (Exception $e)
{
$templateData = [
'e' => $e,
];
if ($config->phalcon->debug)
{
echo render(rtrim($config->phalcon->viewsDir, '/').'/error/exception_debug.phtml', $templateData);
}
else
{
echo render(rtrim($config->phalcon->viewsDir, '/').'/error/exception.phtml', $templateData);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question