dqby43944 2011-10-30 00:07
浏览 78
已采纳

如何在Codeigniter中使用包含和基本模板?

I have worked with a custom php framework and django templates in the past, both of which support what I can describe as "base templates". Meaning you have a file where you have your headers and footers and a div lets say with the id "content". Now everything in your view files contain only the portion of code to fill that "content" div, the headers and footers are put in place by that base template.

How can I implement this sort of a "base layout" in codeigniter. And if that's not possible then how can I tell all my views to include a header.php and a footer.php file at the top and bottom of all my views respectively without having to add those includes manually to each view?

  • 写回答

3条回答 默认 最新

  • douxun4860 2011-10-30 14:54
    关注

    Thanks for the answers guys but I decided to go with the following answer that was given by jruzafa in this question:

    How to Deal With Codeigniter Templates?

    Since it does exactly what I wanted and doesn't require any additional extensions:

    I've tried several ways to do codeigniter templates and the way that I stay is the fastest and simplest, is as follows.

    In controller:

    >     //Charge the view inside array
    >     $data['body'] = $this->load->view('pages/contact', '', true);
    > 
    > 
    >     //charge the view "contact" in the other view template
    >     $this->load->view('template', $data);
    

    In view template.php:

    > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    > "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html
    > xmlns="http://www.w3.org/1999/xhtml" xml:lang="es">  <head> 
    >     <title>Template codeigniter</title>  </head>  <body> 
    >     <div> 
    >         <?=$body?>
    >     </div> 
    >     <div class="clear"></div> 
    >     <div>Footer</div> 
    >     </div>  </body>  </html>
    

    $body is the view contact.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行