0
votes

I have this custom error handler:

`class AppError extends ErrorHandler {

function error404($params) { $this->controller->layout = 'public'; $this->controller->set('title','Droptor Page Not Found'); parent::error404($params); } }`

And I can't seem to use any layout that has this: $javascript->link('jquery',true)

So the JS helper isn't loaded. But if I include this in the controller: var $helpers = array('javascript'); it still doesn't work. Nor does App::import('Helper', 'javascript');

2

2 Answers

2
votes

Crap, I didn't read your question.

To add a helper to your error controller, just add this line:

$this->controller->helpers = array('Javascript');

There are two ways to do it:

First, you can create an app_controller to include every component and helper that you need on all your controllers.

Second, you can load the specific resources needed to your error controller. Create a file named error.php in your app's root (NOT webroot) with the following code:

<?php
class AppError extends ErrorHandler  {
    function error404($params) {
        $this->controller->helpers = array('Javascript');
        parent::error404($params);
    }
}

You can also set a custom title with

$this->controller->set('title_for_layout', "We couldn't find what you are loooking for");

Good luck.

1
votes

First off, you don't need to create your own handler if all you're doing is handling a common error type, such as 404. Custom error handlers are for your application specific errors.

If you want to simply change the layout of your page when you get a 404 error, this has been answered over here.

function beforeRender() {
    if($this->name == 'CakeError') {
        $this->layout = false;
    }
}

And you can cause it using the line:

$this->cakeError('error404');