laravel CakePHP 2.3 的模板引擎
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14818602/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Template engine for CakePHP 2.3
提问by Patrick Maciel
I want to use Smartyor Blade(Laravel) template engine in CakePHP 2.3. It's possible?
我想在 CakePHP 2.3 中使用Smarty或Blade(Laravel) 模板引擎。这是可能的?
If yes, how?
如果是,如何?
If you know other template engines for CakePHP, tell me.
如果您知道 CakePHP 的其他模板引擎,请告诉我。
回答by burzum
Yes it is possible, you'll have to wrap the vendor lib in a view class extending the base view class of CakePHP.
是的,这是可能的,您必须将供应商库包装在扩展 CakePHP 的基本视图类的视图类中。
But template engines are an useless overhead and it does not matter much if the designer has to learn something like {Foo.field} vs echo $foo['field'];.
但是模板引擎是一个无用的开销,如果设计者必须学习诸如 {Foo.field} 与 echo $foo['field']; 之类的东西,这无关紧要。
Just google for "cakephp smarty" and "cakephp twig view" and you'll find something. And if you really want that overhead, even if it is cached, I would go for twig over Smarty.
只需谷歌搜索“cakephp smarty”和“cakephp twig view”,你就会找到一些东西。如果你真的想要这个开销,即使它被缓存,我也会选择 Smarty 上的树枝。
A modern, OOP based view solution for CakePHP is https://github.com/jameswatts/cake-toolkit, you can build your custom objects, inherit them as needed, overwrite them... the usual OOP stuff. And it could be even combined with a template engine.
CakePHP 的一个现代的、基于 OOP 的视图解决方案是https://github.com/jameswatts/cake-toolkit,您可以构建自定义对象,根据需要继承它们,覆盖它们......通常的 OOP 东西。它甚至可以与模板引擎结合使用。
回答by Alireza Rahmani Khalili
this may help u http://bakery.cakephp.org/articles/tclineks/2006/10/27/how-to-use-smarty-with-cake-smartyview
这可能会帮助你http://bakery.cakephp.org/articles/tclineks/2006/10/27/how-to-use-smarty-with-cake-smartyview
but for The decision to use Smarty over traditional native PHP templating should not be taken lightly. Although Smarty is clearly a great tool for simple templating, its functionality is still only a subset of what might be needed in large - scale projects. Although it can be extended with native PHP through the use of the {php } and {/php } tags, doing so rather defeats the purpose of using safe templates in the first place. Indeed, Smarty ' s own Web site states that “ embedding PHP code into templates is highly discouraged. ” The skills and experience of any other developers working with you on the project are likely to be the deciding factor. If you are the sole engineer working on a project, it is almost certainly better to use native templating. Conversely, if the project requires a number of designers and HTML specialists working on the output from your scripts, Smarty templates are a much safer bet, because they allow such individuals to manipulate the display logic of your application to their hearts ' content, without touching the PHP code behind it.
但是对于使用 Smarty 而不是传统的原生 PHP 模板的决定不应该掉以轻心。虽然 Smarty 显然是一个很好的简单模板工具,但它的功能仍然只是大型项目中可能需要的一个子集。虽然它可以通过使用 {php} 和 {/php} 标签用原生 PHP 进行扩展,但这样做首先违背了使用安全模板的目的。事实上,Smarty 自己的网站声明“非常不鼓励将 PHP 代码嵌入到模板中。” 在项目中与您合作的任何其他开发人员的技能和经验可能是决定性因素。如果您是从事项目的唯一工程师,那么使用原生模板几乎肯定会更好。反过来,