CodeIgniter或PHP等价于Rails部分和模板 [英] CodeIgniter or PHP Equivalent of Rails Partials and Templates

查看:114
本文介绍了CodeIgniter或PHP等价于Rails部分和模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在CodeIgniter,或核心PHP;是否有相当于Rails的视图partials和模板?

In CodeIgniter, or core PHP; is there an equivalent of Rails's view partials and templates?

一个部分将允许我渲染视图中的另一个视图片段。我可以有一个共同的 navbar.php 视图,我可以指向我的 homepage.php 视图里面。模板将在一个地方定义HTML页面的整个外壳,并让每个视图只填充正文。

A partial would let me render another view fragment inside my view. I could have a common navbar.php view that I could point to the inside my homepage.php view. Templates would define the overall shell of an HTML page in one place, and let each view just fill in the body.

我在CodeIgniter文档中找到的最近的事情是加载多个视图,其中几个视图在控制器中顺序渲染。看起来奇怪的是,在控制器中控制我的页面的视觉外观。 (即移动导航栏我的设计师必须编辑控制器)。

The closest thing I could find in the CodeIgniter documentation was Loading multiple views, where several views are rendered sequentially in the controller. It seems strange to be dictating the visual look of my page inside the controller. (i.e. to move the navbar my designer would have to edit the controller).

我一直在堆栈溢出来完成这个。我找到了此网页,其中介绍了模拟部分与 ob_start 。这是CodeIgniter中推荐的方法?

I've been searching on stackoverflow for a PHP way to accomplish this. I have found this page, which talks about simulating partials with ob_start. Is that the recommended approach inside CodeIgniter?

推荐答案

我可能会打破一些MVC规则,片段,并从需要它们的其他视图中加载它们,CodeIgniter样式。几乎所有的视图分别在顶部和底部加载页眉和页脚视图:

I may be breaking some MVC rule, but I've always just placed my "fragments" in individual views and load them, CodeIgniter style, from within the other views that need them. Pretty much all of my views load a header and footer view at the top and bottom, respectively:

<? $this->load->view( "header" ); ?>
//Page content...
<? $this->load->view( "footer" ); ?>

头文件可以以相同的方式包含NavBar等。

The header could then include a NavBar in the same fashion, etc.

这篇关于CodeIgniter或PHP等价于Rails部分和模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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