Zend_Config_Ini 中的 Zend_Form_Element
目前,我正在从一个 ini 文件加载表单元素定义,如下所示:
[tickets] ; tablename
ticket_number.name = "ticket_number"
ticket_number.type = "text"
ticket_number.label = "Ticket ID: "
ticket_number.options.validators.alnum.validator = "alnum"
ticket_number.options.validators.strlen.validator = "StringLength"
ticket_number.options.validators.strlen.options.min = "6"
ticket_number.options.validators.strlen.options.max = "20"
assigned_date.name = "assigned_date"
assigned_date.type = "text"
assigned_date.label = "Entered Date: "
现在假设我有一个表单元素(选择/下拉框),并且我想从数据库(查找表)加载选项,是有没有一种方法可以在表单元素 ini 配置中自动配置它,或者是否必须在创建元素时在表单类中完成?
Currently I am loading form element definitions from an ini file that looks like this as an example:
[tickets] ; tablename
ticket_number.name = "ticket_number"
ticket_number.type = "text"
ticket_number.label = "Ticket ID: "
ticket_number.options.validators.alnum.validator = "alnum"
ticket_number.options.validators.strlen.validator = "StringLength"
ticket_number.options.validators.strlen.options.min = "6"
ticket_number.options.validators.strlen.options.max = "20"
assigned_date.name = "assigned_date"
assigned_date.type = "text"
assigned_date.label = "Entered Date: "
Now lets say I have a form element (select / dropdown box), and I want to load the options from a database (lookup table), is there a way to automatically configure that within the form elements ini config, or does that have to be done within the form class upon creation of the element?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,有很多方法可以做到这一点,问题是你是否真的想这样做。
可能的方法:
multiOptions
列表。multiOptions
值注入到Zend_Config
文件中。$form->getElement('name')->setMultiOptions(array(..))
设置 multiOptionsWell, there are ways to do this, the question is whether you actually want to do this.
Possible ways to do it:
multiOptions
list based on some option values which you provide in your ini file.multiOptions
values into theZend_Config
file.$form->getElement('name')->setMultiOptions(array(..))