如何配置 Zend 自动加载器在默认路径之前加载资源的自定义路径

发布于 2024-09-12 04:32:43 字数 262 浏览 0 评论 0原文

单独但相关如何动态覆盖表单和/或使用 Zend 进行视图?

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

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

Separate but related to How to dynamically override forms and/or views using Zend?.

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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

燕归巢 2024-09-19 04:32:44

就像在另一个问题中一样,您需要使用工厂类。此类将在预定义目录中检查新表单或默认表单是否存在。

您需要做的就是:

// $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

然后,在您的控制器中:

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

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.

All you will need to do is something like:

// $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();

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');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文