Codeigniter常用模板 [英] Codeigniter common templates

查看:137
本文介绍了Codeigniter常用模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个网站有100个不同的网页。每个页面都使用一个公共页眉和页脚。在标题内是来自数据库的一些动态内容。

Let's say that I have a website that has 100 different pages. Each page uses a common header and footer. Inside the header is some dynamic content that comes from a database.

我希望避免在每个控制器中都有代码,并且将该常用代码传递到视图中。

I'd like to avoid having to have code in every single controller and action that passes this common code into the view.

function index()
{
    // It sucks to have to include this on every controller action.
    data['title'] = "This is the index page";
    data['currentUserName'] = "John Smith";

    $this->load->view("main_view", data);
}

function comments()
{
    // It sucks to have to include this on every controller action.
    data['title'] = "Comment list";
    data['currentUserName'] = "John Smith";

    $this->load->view("comment_view", data);
}



我意识到我可以重构代码,使公共部分在单个函数并且该函数由动作调用。这样做会减少一些疼痛,但它仍然不正确,因为我仍然必须每次都调用该函数。

I realize that I could refactor the code so that the common parts are in a single function and the function is called by the action. Doing so would reduce SOME of the pain, but it still doesn't feel right since I'd still have to make a call to that function every time.

这是正确的处理方式?

推荐答案

ve也使用上面引用的模板库 - http://www.williamsconcepts.com/ ci / codeigniter / libraries / template /

I've also used the template library referenced above - http://www.williamsconcepts.com/ci/codeigniter/libraries/template/

这是最近出现的另一个模板库 - http://philsturgeon.co.uk/code/codeigniter-template

This is another template library that came out recently - http://philsturgeon.co.uk/code/codeigniter-template

我没有研究两者之间的差异,但我知道创建它们的人都是Codeigniter社区的强大贡献者。

I haven't looked into the differences between the two much but I know that the people who created them are both strong contributors to the Codeigniter community.

这篇关于Codeigniter常用模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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