我刚刚重新格式化了我的CakePHP应用程序的默认布局。通过将几乎所有内容放在html助手方法中,我尽可能地消除了尽可能多的内联html。
这很有趣,但我想知道我从这个练习中获得了什么好处,如果有的话?
<?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;
?>
我认为至少它看起来很好,紧凑而且易读。在这种情况下,我应该注意哪些陷阱?我需要注意任何速度问题吗?
我喜欢它 - 但也不喜欢。
我想我需要被说服去做一个选择。
如果你想知道,当查看源代码时,implode会在html中放置漂亮的换行符。
<?php ?>
标签而硬生生添加中间步骤。 - user229044