这是overkill,还是良好的使用CakePHP的HTML助手? [英] Is this overkill, or good use of CakePHP's HTML helper?

查看:214
本文介绍了这是overkill,还是良好的使用CakePHP的HTML助手?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚重新格式化我的CakePHP应用程序的默认布局。我通过将几乎所有内容放在html helper方法中尽可能多地排除了内联html。

I just reformatted the default layout of my CakePHP application. I eliminated as much in-line html as possible by putting almost everything inside the html helper methods.

这很有趣,但我想知道我获得了什么好处

It was fun, but I'm wondering what benefit I've gained from this exercise, if any?

<?php
    $output = implode("\n", array(
        $html->docType(),
        $html->tag('html', implode("\n", array(
            $html->tag('head', implode("\n", array(
                $html->charset(),
                $html->tag('title', 'Title For App'),
                $html->css('css', NULL, array('media' => 'screen,print')),
                $html->css('print', NULL, array('media' => 'print')),
                $html->script(array('cufon', 'jquery','external'))
            ))),
            $html->tag('body', implode("\n", array(
                $html->tag('div', $content_for_layout, array('id' => 'wrapper')),
                $html->scriptBlock('Cufon.now();')
            )))
        )), array('xmlns' => 'http://www.w3.org/1999/xhtml'))
    ));
    echo $output;
?>

我想至少它看起来不错,紧凑,在这种情况下我应该注意什么陷阱?我应该知道任何速度问题吗?

I suppose at least it looks nice and compact, and is pretty readable. What pitfalls should I be aware of in this scenario? Should I be aware of any speed issues?

我喜欢它—

I like it — and I don't.

我想我需要说服一种方式或另一种方式。

I guess I need convincing one way or the other.

推荐答案

我在Google群组中讨论过这个问题几年前。最终,你会意识到,它不会产生很大的区别,你的方式,直到你需要编程操作的东西 - 然后,如果你去的HTML路由,你会发现你的代码用 <?php & ?> 或字符串连接或双引号变量替换。

I had this discussion in the Google group some years back. Eventually, you'll realise that it doesn't make a lot of difference which way you do it until you need to programatically manipulate stuff - then, if you went the HTML route, you'll find your code peppered with <?php & ?> or string concatenations or double quote variable substitutions.

应用程序下线,我更喜欢维护比标记更帮助的那些。

Now, many applications down the line, I prefer maintaining the ones with more helper than markup.

有很多HTML没有被帮助者覆盖,所以你不能避免混合,但您可以通过尽可能使用助手最小化复杂性和混乱。当您开始使用表单时,您会收到很多安全内容,而且ID和NAME的格式符合 CakePHP 的格式。

There is a lot of HTML that isn't covered by helpers, so you can't avoid a mix, but you can minimise complexity and confusion by using helpers wherever possible. When you start using forms, you get a lot of security stuff thrown in and IDs and NAMEs formatted the way CakePHP prefers.

PHP CakePHP 。为什么只使用半语言或半个框架?

PHP and CakePHP are built for this. Why only use half a language or half a framework?

这篇关于这是overkill,还是良好的使用CakePHP的HTML助手?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆