$this->addElement('type', 'id', array('specs')) VS new Zend_Form_Element_Type('id') ;
优点和缺点是什么:
$this->addElement('type', 'id', array('specs'))
vs
new Zend_Form_Element_Type('id');
我认为第二个更可取,因为更具可读性并提供自动完成功能。
What are the Pro's and Con's of:
$this->addElement('type', 'id', array('specs'))
vs
new Zend_Form_Element_Type('id');
I think the second is preferable because more readable and offers auto-completion.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Zend Framework 提供了这种灵活性,以便您可以根据需要定制 API。所以,答案是“这取决于”...
在我看来,如果您从配置文件获取表单元素数据(例如,您可能需要在开发或生产过程中经常修改表单元素),则数组接口可能是更好的选择您的应用程序的),而对象创建界面看起来“更干净”并且不太容易出错(正如您所说,您可以从 IDE 获得自动完成功能)。
希望有帮助,
The Zend Framework provides this flexibility so that you can tailor the API to your needs. So, the answer is "it depends"...
In my opinion, the array interface could be prefereable if you get the form elements data from a configuration file (for instance, you might need to modify often the form elements during development or production of your application), while the object creation interface looks "cleaner" and is less error prone (you can get auto completion from your IDE, as you say).
Hope that helps,