如何在Codeigniter中使用包含和基本模板? [英] How to use includes and base templates in Codeigniter?

查看:82
本文介绍了如何在Codeigniter中使用包含和基本模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去,我使用过自定义的php框架和django模板,它们都支持我称之为基本模板的内容。意味着您有一个文件,其中有您的页眉和页脚,以及一个div,其ID为 content。现在,视图文件中的所有内容仅包含填充该内容 div的部分代码,页眉和页脚已通过该基本模板放置到位。

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.

如何我在codeigniter中实现了这种基本布局。而且如果那不可能,那么我如何告诉我所有的视图在其所有视图的顶部和底部分别包含header.php和footer.php文件,而不必将这些包含手动添加到每个视图中?

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?

推荐答案

谢谢大家的回答,但我决定采用jruzafa在此问题中给出的以下答案:

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

如何处理Codeigniter模板?

因为它完全符合我的要求,并且不需要任何其他扩展名:

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


我尝试了几种方法来制作codeigniter模板,而我
留下的最快,最简单的方法如下。

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

在控制器中:



>     //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);




在view template.php中:

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是视图联系人。

$body is the view contact.

这篇关于如何在Codeigniter中使用包含和基本模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆