5

使用这些类对性能或安全问题有好处吗,因为我们知道 HTML 应该是纯 HTML。

例子:

在 Codeigniter Framewỏrk 中:

 echo form_input(array('name' => 'one'));

被称为

<input type="text" name="one"/>

哪个更好?

4

2 回答 2

4

Copied from Phil Sturgeon Blog:
The extra layer of abstraction, combined with helper extending/overriding makes it very easy to change simple bits of logic throughout your application output with minimal fuss.

To explain, I'll use an example.

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

First you will see the standard HTML way to do it, with the site_url() function used to create the link to the form action. Second you will see the form_open() tag - and in this example its shorter too, wahey!

I wanted a way to set accept-charset="UTF-8" in all my forms to help keep my data all UTF-8 in CodeIgniter. If I was using just HTML then I would have to go through all my forms and add that in myself, which would be wasting time I could have spent at the pub.

Instead, as CodeIgniter allows you to extend helpers, I just made my own slightly modified form_open() in application/helpers/MY_form_helper.php which contained this logic.
Because I was using PHP to wrap my useful data, I could make one simple change and update all of my tags.

The main problem is people are looking at these HTML helper functions and seeing them purely as different syntax.

For complete article visit:
http://philsturgeon.co.uk/blog/2009/12/Why-CodeIgniter-HTML-helper-functions-rock

于 2013-02-15T05:02:11.267 回答
2

这是一个很好的问题。我认为最终归结为个人喜好。就我个人而言,我不喜欢使用表单助手,但我当然可以看到使用它们的好处,如果我正在处理一个大项目,我会尝试使用它们。因为就像 Phil Sturgeon 所说,当您想要对所有表单字段进行站点范围内的更改时,它会容易得多。

虽然我很想看看使用表单辅助函数是否会影响性能。使用 PHP 生成 HTML 肯定会比正常编写 HTML 有性能损失吗?

于 2013-02-15T11:47:17.757 回答