什么是codeigniter中的layout / template / themes [英] What is layout/template/themes in codeigniter
问题描述
我是新的codeigniter,我觉得麻烦布局/模板/主题在codeigniter。
我不知道应该使用其中的一个..
我能做的最好的方法是什么?如果我想要制作一个网站免费的 html / css模板如
I'm new in codeigniter, I feel trouble about layout/template/themes in codeigniter.
I don't know when should using one of them..
What is the best way that i can do? if i want to make a website with free a html/css template like
goodnatured
|--img
|--img01.jpg
|--css
|--style.css
|--js
|--jquery.js
|--index.html
任何人都可以告诉我一个教程,建议,。 ..
Anyone can tell me a tutorial, suggest, ... thanks
推荐答案
我只是写了一些额外的库( application / libraries / display_lib.php
)用于渲染温度和类似的页面块。
这样的东西:
I just write little additional library(application/libraries/display_lib.php
) for rendering tempates and similar page blocks.
Something like this:
class Display_Lib{
private $_CI;
private $_template_data;
public function __construct()
{
$this->_CI =& get_instance();
}
public function set($key, $value)
{
$this->_template_data[$key] = $value;
}
public function get($key)
{
return $this->_template_data[$key];
}
public function get_template_data()
{
return $this->_template_data;
}
public function display_page($view, $data = array())
{
$this->set('content', $this->_CI->load->view($view, $data, TRUE));
$this->_CI->load->view('templates/main_template', $this->get_template_data());
}
}
在自动加载中设置此库:
Set this library in auto load:
$autoload['libraries'] = array('session', 'database', 'display_lib');
并在控制器中调用:
class Main extends CI_Controller{
public function index()
{
$some_data = array();
$this->display_lib->display_page('views/main_view', $some_data);
}
}
模板示例:
<!DOCTYPE html>
<html lang="en">
<head>
<base href="<?=base_url();?>">
<meta charset="utf-8">
<link rel="icon" href="<?=site_url('img/favicon.ico')?>" type="image/x-icon"/>
<link rel="stylesheet" href="<?=site_url('css/style.css');?>" type="text/css" media="screen, projection"/>
<script type="text/javascript" src="<?=site_url('js/jquery-1.10.2.min.js');?>"></script>
<title>Some page title</title>
</head>
<body>
<header></header>
<div class="auth_wrapper">
<div class="content">
<?=$content;?>
</div>
<div class="buffer"></div>
</div>
<footer></footer>
</body>
</html>
和 application / views / main_view
:
<div>Come content will be here</div>
此lib允许使用模板和渲染来自控制器的视图。
This lib allow to use templates and render views from controllers.
这篇关于什么是codeigniter中的layout / template / themes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!