在全局应用程序级别更改默认的 Zend Form Decorator?
当然,我不想改变库/Zend。 我知道我可以创建类 My_Form 来扩展 Zend_Form 并设置自定义装饰器。然后,每个表单都会扩展新类 My_Form...
有没有办法在某些插件或引导程序中设置 Zend Form Decorator(更改默认装饰),而不更改现有表单?
或者,覆盖所有表单的默认表单装饰器的最佳方法是什么?
Of course, I don't want to change library/Zend.
I know that I can create class My_Form which extends Zend_Form and setup custom decorator. Than, every form extends new class My_Form...
Is there any way to set Zend Form Decorator(change default decoration) in some plugin or bootstrap, without changing existing forms ??
Or, What is the best way to override default form decorator for all forms?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不确定我的回答是否有帮助,但你可以看看。
有一种方法可以用您自己的装饰器替换 ZF 装饰器,而无需编辑表单本身。
解决方案#1:
描述的方法这里。或者简而言之:
假设您有一个表单:
然后在 application.ini 中
添加一个新文件 application/views/helpers/FormText.php
就是这样。
解决方案#2:
让我们有这个抽象类:
然后是一个后代。
onApply() 方法中可以是任何适合您的内容。例如,添加或删除装饰器。然后,您可以像这样在表单上调用此样式:
这允许您操作表单表示,但不直接更改它。
I am not sure whether my answer will be of help, but here you go.
There is a way of substituting ZF decorators with your own decorators without editing the forms themselves.
SOLUTION #1:
The method described here. Or in short:
Let's say you've got a form:
Then have in application.ini
Add a new file application/views/helpers/FormText.php
And that is it.
SOLUTION #2:
Let's have this abstract class:
And then a descendant.
In the onApply() method could be anything that suits you. Adding or removing decorators, for example. Then you can call this styling upon your form like this:
which allows you to manipulate the form representation but without changing it directly.
许多人都尝试过,据我所知,没有人在不扩展 Zend_Form 的情况下成功做到这一点。请参阅此 和 此用于子-最优解。
Many have tried, none that I know of succeeded in doing it without extending Zend_Form. See this and this for sub-optimal solutions.
我有一个解决方案。您可以在 bootsrap 中定义装饰器。
例如:-
现在您可以将它用于所有表单文本字段。
例如:-
所以你可以使用这个的一些全局装饰器。
I have one solution. You can define decorators in bootsrap.
ex:-
Now you can use it for all form text field.
ex:-
So you can use some global decorator form this one.
这是完整的解决方案。
在“.ini”文件中为装饰器设置文件夹:
接下来,为装饰器使用相同名称以覆盖默认装饰器。
例如,要替换默认的“DtDdWrapper”装饰器,
您可以使用 Application_Form_Decorator_DtDdWrapper:
装饰器将由该名称的最后一部分加载。
Here is complete solution.
Set folders for your decorators in ".ini" file:
Next, use same name for your decorator to override default decorator.
For example, to substitute default "DtDdWrapper" decorator,
you can use Application_Form_Decorator_DtDdWrapper:
Decorator will be loaded by last part of that name.