您如何在ErrorHanlder中包含javascript帮助器? [英] How do you include the javascript helper in the ErrorHanlder?

查看:75
本文介绍了您如何在ErrorHanlder中包含javascript帮助器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个自定义错误处理程序:

I have this custom error handler:

`类AppError扩展了ErrorHandler {

`class AppError extends ErrorHandler {

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

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

而且我似乎无法使用具有以下格式的任何布局:
$ javascript-> link('jquery',true)

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

因此未加载JS帮助器。但是,如果我将其包含在控制器中: var $ helpers = array(’javascript'); 仍然无效。 App :: import('Helper','javascript');

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');

推荐答案

废话,我没有看你的问题。

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:

首先,您可以创建 app_controller 包含所有控制器上所需的每个组件和帮助程序。

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

第二,您可以将所需的特定资源加载到错误控制器中。使用以下代码在应用程序的根目录(非Webroot)中创建一个名为 error.php 的文件:

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");

祝你好运。

这篇关于您如何在ErrorHanlder中包含javascript帮助器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆