class Home extends CI_Controller {
public function index(){
$this->load->view(" top ");
$this->load->view(" home.html "); 
$this->load->load(" foot "); 
}
}
//如果模板是html文件的话,就需要带.html后缀;如果是.php的话就不需要,$this->load->view(" home "); 
//也可以载入多个模板视图
//从文件夹里面载入多个视图
$this -> load -> view(" Index/top ");
$this -> load -> view(" Index/home ");
$this -> load -> view(" Index/footer ");
/**
* 分配给模板视图变量数据
*/
$data[' title '] = '你好 啊';
$this -> load -> view(" Index/top " ,$data );
注意:载入多个视图的时候,其中一个视图分配了数据变量的话,其他的视图也自动默认分配了数据变量
$data[ " name " ] = array(
" 张三 " , " 李四 " , " 王五 "
);
$this -> load -> view( " Index/home " , $data);视图中:
<?php echo $title; ?>
载入辅助函数
1,在控制器中手动载入
$this -> load -> helper(" name ");
url , site_url , base_url2,自动载入辅助函数
$autoload['helper']=array(url);
3,共用函数是在system/core/common.php文件中写的
 以上就是CI框架随记1的内容,更多相关内容请关注PHP中文网(www.php.cn)!
                        
                        每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
                
                                
                                
                                
                                
                                
                                Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号