PHP include best practices question

前端 未结 10 1737
一生所求
一生所求 2020-11-29 19:40

I have been learning syntax for PHP and practicing it. I come from a .NET background so masterpages always made things pretty easy for me when it came to headers and footer

10条回答
  •  失恋的感觉
    2020-11-29 20:15

    This is a perfectly fine method, as long as your site doesn't outgrow the 20 pages threshold. I'd however advise to use include() in function style, not as construct, and place these templates in a separate subfolder. If there is no PHP code in them, also use a .htm file extension (htm designating partial html).

     include("template/main/header.htm");   // would still parse PHP code!
    

    The disadvantage with this approach is, that you somewhen end up injecting HTML through global variables into it. $HEAD=''; include("../header.htm"). Which is not bad per se, but can quickly amass cruft.

提交回复
热议问题