如何使用 Zend 动态覆盖表单和/或视图? [英] How to dynamically override forms and/or views using Zend?

查看:33
本文介绍了如何使用 Zend 动态覆盖表单和/或视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Zend 开发一个 Web 应用程序,我们希望随附一些默认表单和视图.我们希望客户端能够创建自定义表单和/或视图,这些表单和/或视图可以放置在另一个可以覆盖默认表单的目录中.IE、Zend 会检查是否存在任何自定义表单(或视图),如果存在,则加载它们,否则加载默认的.

I'm working on a web application using Zend that we'd like to ship with some default forms and views. We'd like the client to be able to create custom forms and/or views that could be placed in another directory that could override the default forms. IE, Zend would check to see if any custom forms (or views) existed, and if so, load those, otherwise load the default ones.

使用 Zend 可以做到吗?

Is this possible to do using Zend?

我已经考虑过为默认情况下只会调用父构造函数的每个表单创建子类,但这似乎有点麻烦.

I already thought about creating subclasses for every form that by default would just call the parent constructor, but that seems like a bit of a hack.

推荐答案

使用自定义和默认前缀/路径配置的工厂/服务类如何,其工作是实例化请求的表单.这个工厂类的工作是首先检查自定义表单的存在并回退到默认表单.

How about a factory/service class, configured with your custom and default prefixes/paths, whose job is to instantiate the requested form. It would be the job of this factory class to check first for the presence of a custom form and to fallback to the default form.

因此,您可以让名为 My_Form_Default_User 之类的默认表单出现在 application/forms/default 中,而您的默认表单名为 My_Form_Custom_User 之类的名称出现在 application/forms/custom 中.然后客户端代码可以调用类似 My_FormFactory::createForm('user') 的东西.

So you could have default forms named something like My_Form_Default_User appearing in application/forms/default and your default forms named something like My_Form_Custom_User appearing in application/forms/custom. Then client code could call something like My_FormFactory::createForm('user').

另一种可能是将两种情况下的表单命名为相同的内容(例如:My_Form_User),然后使用两个位置的路径配置自动加载器.如果自动加载器找到自定义表单,很酷.如果不是,它会回退到默认位置.但这种方法对我来说似乎有点冒险.

An alternative might be to name the forms the same thing (Ex: My_Form_User) for both cases, but then configure the autoloader with paths to both locations. If the autoloader finds the custom form, cool. If not, it falls back to the default location. But that approach seems a bit dicier to me.

这篇关于如何使用 Zend 动态覆盖表单和/或视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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