Question
In the 'default'
layout for my Lithium install I have the following code:
<?php echo $this->html->script(array('jquery-1.7.1-dev.js')); ?>
For all normal requests (e.g. /path/to/framework/users/login
, where Users
is a model and there is a UsersController::login
method) this is rendered correctly as:
<script type="text/javascript" src="/path/to/framework/js/jquery-1.7.1-dev.js"></script>`
However, in views that are rendered by my error handling code the /path/to/framework
is omitted and it is rendered as:
<script type="text/javascript" src="/js/jquery-1.7.1-dev.js"></script>
Why is the helper not rendering the path correctly in this case?
Error-handling approach
My error handling approach is based on a number of online tutorials. In config/bootstrap/errors.php
I have:
$exampleConditions = array('type' => 'Exception');
ErrorHandler::apply('lithium\action\Dispatcher::run', $exampleConditions, function($info, $params) {
return ErrlogsController::handleError($info, $params);
});
ErrorHandler::run();
In the ErrlogsController
class I have:
public static function handleError($info, $params) {
// (Code to save error info to DB omitted from example)
$view = new View(array(
'paths' => array(
'template' => '{:library}/views/{:controller}/{:template}.{:type}.php',
'layout' => '{:library}/views/layouts/{:layout}.{:type}.php'
)
));
return $view->render('all', array(), array(
'template' => '404',
'controller' => 'errlogs',
'layout' => 'default',
'type' => 'html'
));
}
I have code dived as deep as lithium\template\view\Renderer::applyHandler
and the File
adapter which do the actual rendering to try and understand this behaviour, and I have also tried adding an 'elements'
key to the 'paths'
array for $view
but I am a bit stuck. Any suggestions or help is much appreciated.
Background
The below two links show how to use ErrorHandler::apply
function (as in above code) and also ErrorHandler::config
. Both use the same approach as in the above code to render a view, and the first is also tangentially interesting to this post though because it also shows how to handle different types of errors differently.
- Example one - masom
- Example two - Lithium wiki - shows how to use the
ErrorHandler::apply
function