将数据放置在视图中的最佳方式 (MVC)
在我正在使用的框架中,如果我想在视图中呈现数据,我会这样做:
<h1><?php echo $this->header ?></h1>
最近我发现了 xTemplate 并注意到它使用字符串占位符,因此 xTemplate 中的上述代码将是
<h1>{HEADER}</h1>
:视图还可以,而且比执行 str_replace 更快,但我最近开始与设计师合作,我认为 html 中的很多 php 标签可能会让他感到困惑。
我想知道您对这个问题的想法。
谢谢。
注意:这可能是主观的,但我真的想找到最好的方法,或者至少知道这两种方法的所有优点和缺点。
In the framework I am working with, if I want to present data in a view I do this:
<h1><?php echo $this->header ?></h1>
Recently I discovered xTemplate and noticed it uses string placeholders, so the above code in a xTemplate would be:
<h1>{HEADER}</h1>
I always thought that a little php in the view was ok and was also faster than doing a str_replace, but I have recently started working with a designer and I think lot's of php tags in the html might confuse him.
I would like to know your thoughts on this subject.
Thanks.
Note: This might be subjective but I really want to find out the best way or at least know all the pros and cons of both of these approaches.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
PHP 被设计为一种模板语言。我认为在模板引擎之上创建模板引擎没有任何意义。
比较
第一个变体真的很复杂吗?
如果您尝试使用 Smarty,您将会非常惊讶它的复杂程度。。这是纯粹的邪恶: http://www.smarty.net/manual /en/language.function.foreach.php
是不是比 PHP 的 foreach 更容易阅读?别让我笑。
邪恶的。
除了 PHP 本身之外,不要使用任何模板引擎。
为你的设计师提供足够的辅助功能,他不会抱怨。
PHP is designed as a templating language. I see no point in creating template engines above template engine.
Compare
Is the first variant really complicated?
If you try Smarty, you will be very surprized how complicated it is. It is pure EVIL: http://www.smarty.net/manual/en/language.function.foreach.php
Is it simpler to read than PHP's foreachs? Don't make me laugh.
EVIL.
Don't use any template engines other than the PHP itself.
Provide enough helpers functions to your designer and he will not complain.
有趣的问题。我不知道设计者看到 PHP 会有多困惑,但 PHP 具有以下优点:
Interesting question. I don't know how confused a designer could be by seeing PHP but PHP as the following advantages: