大家都是怎样设计header和footer的啊
我用的是继承的方法,大家有什么好的方法啊,都出来说说,搞得每次都要调用header和footer方法 private function display($data = array(),$script='',$template_dir = '',$renderHF = true){
if(!is_array($data)){
$data =array($data);
}
$this->load->vars($data);
if(empty($template_dir)){
$template_dir = strtolower($this->_controller);
}
if(empty($script)){
$script = strtolower($this->_action);
if(empty($script)){
$script = 'index';
}
}
$template_dir = $template_dir.'/'.$script.'.php';
if($renderHF){
$this->load->view('/header.php');
$this->load->view($template_dir);
$this->load->view('/footer.php');
}else{
$this->load->view($template_dir);
}
} 我看到有些人直接写在view视图里,却又找不到它们的control,没control怎么传递变量呢 Jeffery Way的视频里有提到过的。
view目录下建立include目录,在里面新建template.php
$this->load->view('include/header');
$this->load->view($template);
$this->load->view('include/footer');
控制器每次调用的时候是这样
$data['record'] = '要传递给视图的数据';
$data['template'] = '控制器对应的视图路径‘;
$this->load->view('include/template', $data);
本帖最后由 大道达人 于 2012-10-10 09:46 编辑
http://codeigniter.org.cn/forums ... iewthread&tid=12209
CIER小站 Zhao.Template(header-content-footer模板和提示设计)
页:
[1]