在Codeigniter中调用1视图,但在所有视图之间共享页眉/页脚? [英] Call 1 view in Codeigniter but share header/footer among all views?

查看:138
本文介绍了在Codeigniter中调用1视图,但在所有视图之间共享页眉/页脚?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Loving Codeigniter,但我发现它令人讨厌,我必须调用的标题,页脚和每个控制器的主视图。

Loving Codeigniter, but I'm finding it annoying that I have to call a header, footer and the main view for each controller.

在所有视图中共享页眉/页脚的最佳方式是最小化代码复制。我不想使用模板引擎。

What is the best way to share a header/footer among all views and minimize replication of code. I don't want to use a template engine.

推荐答案

创建视图,让我们称之为template.php, / p>

create a view, let's call it template.php with this code

<?php 
$this->load->view('header');
$this->load->view($view);
$this->load->view('footer');
?>

在您的控制器上执行

//the name of the view file you want to show, in my case I want to open the login_page.php view that's inside the folder user
$data['view'] = 'user/login_page';
//load the data variable so I can use it across the views
$this->load->vars($data);
//load the template.php view that will load header, user/login_page and footer
$this->load->view('template');

这篇关于在Codeigniter中调用1视图,但在所有视图之间共享页眉/页脚?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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