1
51
我包括来自控制器的视图。我还定义了文件位置,以便于维护。 配置.php
控制器.php
|
2
5
你也可以反过来做。有一个带有页眉/页脚的主页,只包含正文。
|
3
3
在开始使用“视图”或“模板”之前,您所做的一切都是正常的,在这种情况下,您将不再在运行的“控制器”或“操作”中安排内容HTML。 相反,您将加载一个视图,并用值填充它,从而将所有HTML源代码的顺序留给视图,而不是PHP文件。
然后加载布局文件,如下所示:
|
4
3
部分基于Galen和Balus的观点:
|
5
2
smarty . 对于整个应用程序,请考虑使用 framework codeigniter . |
6
1
|
7
1
公认的答案是从2010年开始,在过去的十年里情况发生了变化。
该走的路,现在就走
composer
已经取代了大多数手有线自动装弹机,最佳做法是使用一个单一的
使用
根据环境不可知的方法,使用
|
8
0
这是一个非常好的方法,只要你的网站不超过20页的门槛。不过,我建议在函数样式中使用include(),而不是作为构造,并将这些模板放在单独的子文件夹中。如果其中没有PHP代码,也可以使用.htm文件扩展名(指定部分html的htm)。
这种方法的缺点是,最终会通过全局变量向其中注入HTML。
|
9
0
我知道这已经很晚了,只是想在这个问题上加上我的“便士价值”。
我的建议是为此创建方法,例如我的根是:var/www/htdocs/函数文件位于includes/functions/template中-零件.php.
并用作:
|
10
-1
我喜欢用函数来打印页眉和页脚,而不是包含。这样可以更好地微调变量范围。 |
Daniel Viaño · 将函数移动到不同的文件 6 年前 |
Trojax · 编译多个。c和。h文件 6 年前 |
Stevoisiak · 为什么#包含打破全局变量? 7 年前 |
jaxonjma · 在另一个JSP中动态发送并包含JSP 7 年前 |