如何配置 Zend 自动加载器以在默认路径之前加载资源的自定义路径 [英] How to configure the Zend autoloader to load a custom path for resources before the default path

查看:23
本文介绍了如何配置 Zend 自动加载器以在默认路径之前加载资源的自定义路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

独立但与如何动态覆盖表单有关和/或使用 Zend 的视图?.

我希望 Zend 在为 Web 应用程序加载一组默认表单之前尝试加载自定义表单/视图,以便客户为其应用程序创建自定义表单.

I want Zend to try to load custom forms/views before loading a set of default forms for a web application to let clients create custom forms for their application.

如何配置自动加载器以在默认 Zend 类之前加载不同的路径?

How do you configure the autoloader to load a different path before your default zend classes?

推荐答案

与其他问题一样,您需要使用工厂类.此类将在预定义的目录中检查新表单或默认表单是否存在.

Like in the other question, you'll need to use a factory class. This class will check in a predefined directory the existence of the new form or otherwise the default form.

您需要做的就是:

// $formname is the parameter passed to the factory class
$defaultclassname = "Default_Form_{$formname}";
$classname = "New_Form_{$formname}";
if(file_exists("/path/to/directory/of/new/{$formname}.php"))
    return new $classname();
else
    return new $defaultclassname();

这将在您的工厂类中完成,例如/MyLib/Form/Form_Factory.php

This will be done in your factory class, something like /MyLib/Form/Form_Factory.php

然后,在您的控制器中:

And then, in your controller:

$form = MyLib_Form_Factory::createForm('user');

这篇关于如何配置 Zend 自动加载器以在默认路径之前加载资源的自定义路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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