How to enable javascript helper in ErrorHanlder?

I have this 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 cannot use any layout that has this: $javascript->link('jquery',true)

Thus, the JS helper does not load. But if I include this in the controller: var $helpers = array('javascript');it still doesn't work. AlsoApp::import('Helper', 'javascript');

0
source share
2 answers

Shit, I did not read your question.

To add an assistant to your error controller, simply add this line:

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

:

-, app_controller , .

-, , . error.php (NOT webroot) :

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

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

.

+2

-, , , , , 404. .

, 404, .

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

:

$this->cakeError('error404');
+1

Source: https://habr.com/ru/post/1777335/


All Articles