框架助手,它们有什么用?
我开始研究一些框架。 Code Igniter 尤其让我着迷。但通过搜索文件夹,我发现 system/helpers
包含 21 个 PHP 文件。在这些文件中我们发现了数千个与html、xml、字符串、数组、数字、表单等相关的函数。
这应该很简单,但我真的不明白这些helper
的含义文件。我的意思是:通常被认为是助手的是什么?它们是必需的吗?我可以毫无风险地删除它们吗?
I began looking at some frameworks. Particularly Code Igniter fascinated me. But searching trough the folders I found out system/helpers
that contains 21 PHP files. Inside these files we find thousands of functions related to html, xml, strings, arrays, numbers, forms... etc.
This should be simple, but I really don't understand the meaning of these helper
files. I mean: What is generally considered an helper? Are they required? Could I delete them without risks?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
包括 CodeIgniter 在内的许多框架中的“助手”是指一组函数,这些函数通过将多个进程分组到单个函数中,使简单的例行任务更容易完成。
您可以在此处找到 CodeIgniter 帮助程序的官方文档。
它提供了以下解释:
辅助函数列表及其用途也可以在文档中找到。
Dan
PS. 您不应删除系统目录中的任何文件,因为它们可能是核心所依赖的。您可以创建自己的帮助程序,并将其放置在 application/helpers 目录中。
A "helper" in many frameworks including CodeIgniter refers to a set of functions that make simple, routine tasks easier to accomplish by grouping multiple processes into a single function.
The official documentation for CodeIgniter helpers can be found here.
It provides the following explanation:
A list of helper functions and what they do can also be found in the documentation.
Dan
PS. You should not delete any files in the system directory as they may be relied upon within the core. You can create your own helpers which are placed in the application/helpers directory.
帮助程序是为了使某些任务变得更容易而提供的功能,例如验证或输入清理。您不应该删除它们,事实上,应该尽可能多地使用它们,因为它们通常做得很好并且经过了良好的测试。
Helpers are functions provided to make some tasks easier, like validation or input sanitizing. You shouldn't delete them, and, in fact, should use them as much as possible, because they are usually well done and well tested.
您永远不应该删除库/框架的文件。它们被设计为“作为一个整体”工作。在用户方面,将库/框架分成几部分的理由很少。所以你可能什么也赢不了,但也有破坏某些东西的风险。
然而,“助手”是一个通用概念,它提供了一些简单的功能,其他组件可以使用(或不使用),而不需要直接实现它。查看 codeigneter 手册,了解该帮助程序适合哪个部分的一些提示。
You should never delete files of a library/framework. They are designed to work "as a whole". On the user side there are very less reason, where it make sense to cut a library/framework into pieces. So you will probably win nothing, but with the risk, that you break something.
However, "Helpers" is a generic concept, that provides some simple functionality, that another component may use (or not), without the need to directly implement it. Look at the codeigneter manual for some hints for which part this helpers are good for.
您当然不应该从框架的核心/系统文件中删除任何帮助程序,因为该功能通常会在其他库中使用,并可能导致各种问题。
您不必在应用程序中使用它们,并且它们不会导致明显的性能问题。
它们一开始可能看起来多余,但例如 CI 非常有帮助(正如您可能期望的那样)。
您可能会争辩说,表单助手或 HTML 助手只会产生开销,您可以自己输入适当的 HTML,但请想一想:
节省您自己所有这些额外的字符,加上拼写错误、打字错误等的风险。Phil
Sturgeon 咆哮道关于助手的使用以及它们为何摇滚,可以是
编辑!
为了证明我的观点而
you certainly shouldn't delete any helper from the core/system files of a framework, as often the functionality will be used in other libraries and can cause all kinds of problems.
You don't have to use them in your app, and they will cause no noticeable performance problems.
They may seem redundant at first, but the CI ones for instance are extremely helpful (as you'd probably expect).
You could argue that the form helper or the HTML helper just generates overhead, and you could type the appropriate HTML out yourself, but think:
Save your self all those extra characters, plus the risk of mispelling, mistyping etc.
Phil Sturgeon had a rant about the use of helpers and why they rock, which can be found here, raising several good points.
Edit
for the sake of proving my point!