框架助手,它们有什么用?

发布于 2024-10-30 23:05:27 字数 228 浏览 2 评论 0原文

我开始研究一些框架。 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

通知家属抬走 2024-11-06 23:05:27

包括 CodeIgniter 在内的许多框架中的“助手”是指一组函数,这些函数通过将多个进程分组到单个函数中,使简单的例行任务更容易完成。

您可以在此处找到 CodeIgniter 帮助程序的官方文档。

它提供了以下解释:

助手,顾名思义,可以帮助您完成任务。每个帮助文件
只是函数的集合
一个特定的类别。有网址
帮助者,协助创建
链接,有表单助手
帮助您创建表单元素、文本
助手执行各种文本
格式化例程、Cookie 助手
设置和读取 cookie、文件助手
帮助您处理文件等。

辅助函数列表及其用途也可以在文档中找到。

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:

Helpers, as the name suggests, help you with tasks. Each helper file
is simply a collection of functions in
a particular category. There are URL
Helpers, that assist in creating
links, there are Form Helpers that
help you create form elements, Text
Helpers perform various text
formatting routines, Cookie Helpers
set and read cookies, File Helpers
help you deal with files, etc.

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.

凉世弥音 2024-11-06 23:05:27

帮助程序是为了使某些任务变得更容易而提供的功能,例如验证或输入清理。您不应该删除它们,事实上,应该尽可能多地使用它们,因为它们通常做得很好并且经过了良好的测试。

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.

长梦不多时 2024-11-06 23:05:27

您永远不应该删除库/框架的文件。它们被设计为“作为一个整体”工作。在用户方面,将库/框架分成几部分的理由很少。所以你可能什么也赢不了,但也有破坏某些东西的风险。

然而,“助手”是一个通用概念,它提供了一些简单的功能,其他组件可以使用(或不使用),而不需要直接实现它。查看 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.

梦与时光遇 2024-11-06 23:05:27

您当然不应该从框架的核心/系统文件中删除任何帮助程序,因为该功能通常会在其他库中使用,并可能导致各种问题。

您不必在应用程序中使用它们,并且它们不会导致明显的性能问题。

它们一开始可能看起来多余,但例如 CI 非常有帮助(正如您可能期望的那样)。

您可能会争辩说,表单助手或 HTML 助手只会产生开销,您可以自己输入适当的 HTML,但请想一想:

   <form action="<?php echo site_url('controller/method'); ?>" method="post">

    // or using the form helper

    <?php echo form_open('controller/method');

节省您自己所有这些额外的字符,加上拼写错误、打字错误等的风险。Phil

Sturgeon 咆哮道关于助手的使用以及它们为何摇滚,可以是

编辑!

为了证明我的观点而

$attributes = array('class' => 'email', 'id' => 'myform');
$hidden = array('hidden_value'=>'1234', 'hidden_value_2' => 'foobar');

echo form_open('email/send', $attributes, $hidden);

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:

   <form action="<?php echo site_url('controller/method'); ?>" method="post">

    // or using the form helper

    <?php echo form_open('controller/method');

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!

$attributes = array('class' => 'email', 'id' => 'myform');
$hidden = array('hidden_value'=>'1234', 'hidden_value_2' => 'foobar');

echo form_open('email/send', $attributes, $hidden);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文