4

我是codeigniter的新手。请告诉我如何在 codeigniter 中集成或安装 html 主题/模板?(我的css文件夹路径=news/css和应用程序文件夹路径=news/application,其中news是我的主文件夹)

-谢谢。

4

3 回答 3

5

这是在 codeigniter 中做模板的一种非常简单、非常强大的方法,而且非常灵活。
http://news.dice.com/2013/02/18/how-to-build-a-to-do-app-with-codeigniter/

忽略标题,大部分课程都是关于在 CI 中设置模板。

请注意,我是从 net.tutsplus.com 上的 jeffrey 方式 CI 教程中第一次接触到这种方法所有这些都值得一试:http: //net.tutsplus.com/sessions/codeigniter-from-scratch/

编辑——好的,这是对帖子的补充。所以在教程中,在 template.php 页面上,你会看到

 $this->load->view($maincontent);

这很酷。但这要好得多:

// load your header views

 $templatefolder = 'beta/';

 if(isset($content01))
 $this->load->view($templatefolder.$content01);

 if(isset($content02))
 $this->load->view($templatefolder.$content02);

 if(isset($content03))
 $this->load->view($templatefolder.$content03);

 // load your footer views 

so instead of calling the view "maincontent", i've put in references to $content1, $content2, etc. Because we are doing if isset none of them are required. that way you can easily send more then one view file to the template. Or none at all if you are just showing a message, etc. Also notice that we have $templatefolder - that way you can easily reuse the template file for other site templates, even with the same content.

in your controller (similar to tutorial) it would be

 $data['content01'] = 'codeigniterrawks';
 $data['content02'] = 'mypetlion';
 // beta template
 $this->load->view( 'template_beta', $data );

note how easy it is if i want to bring in those same view files into a different template

 $data['content01'] = 'codeigniterrawks';
 $data['content02'] = 'mypetlion';
 // alpha template
 $this->load->view( 'template_alpha', $data );
于 2013-02-20T02:41:30.110 回答
0

大约一周前我遇到了这个确切的问题,这个指南真的帮助了我:

http://net.tutsplus.com/tutorials/php/an-introduction-to-views-templating-in-codeigniter/

为了处理 CSS url,我在 config/autoload.php 中的库中添加了“uri”(所以它看起来像这样:

$autoload['libraries'] = array('uri', 'database');)

" type="text/css" 媒体="screen" />

base_url 函数会自动返回您网站的基本 url,即

http://localhost/news/

将参数附加到末尾。

这背后的原因是,如果/当您需要迁移服务器时,您只需更改配置文件中的 base_url,它就会自动更新所有模板和源。

于 2013-02-19T22:45:09.777 回答
0

Try this,

I'm using this and it's very powerful.

https://github.com/philsturgeon/codeigniter-template

于 2013-02-20T07:24:16.553 回答