doulu4316 2013-10-16 11:13
浏览 16
已采纳

在CakePHP中加载页眉和页脚的更好方法是什么?

I am getting my foot wet with CakePHP and wondering what is better to load views. I tried searching but could not find satisfying answer for this small question. If I have to load header and footer along with content, what should be better approach :

1) Using $this->fetch("header") in view.ctp

or 2) I don't know how is it possible but, loading different views one after another from controller like we do in CodeIgniter ($this->load->view("header")).

  • 写回答

1条回答 默认 最新

  • doupapin172773 2013-10-16 11:31
    关注

    As mentioned by user2076809, you'll probably want to use elements for this purpose, to keep things DRY: book.cakephp.org/2.0/en/views.html#elements.

    Be aware though that Cake uses layouts (http://book.cakephp.org/2.0/en/views.html#layouts) to handle the header and footer by default, so take a look at app/View/Layouts/default.ctp and make sure you don't have redundant code there (for example, it has the <head> tag with all the default CSS includes).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部