public function index()
{
$data["header"] = $this->load->view('head_template.php',"",true);
$data["navigation"] = $this->load->view('navigation_template.php',"",true);
$data["footer"] = $this->load->view('footer_template.php',"",true);
$this->load->view('page_view.php', $data, false);
}
在你的“page_view.php”里面
<html>
<body>
<?php
echo $header;
echo $navigation;
echo $footer;
?>
</body>
</html>
您可以在 -http://www.codeignitor.com/user_guide/general/views.html 找到更多信息
包含的代码仅用于模板包含的示例-
class Template extends CI_Controller{
public function __construct(){
parent :: __construct();
}
/**
* TODO: Get the template from database or some configuration file
*
* 1) Get Template hook
* 2) Get Header
* 3) Get Footer
* 4) Get other hooks
*/
public function loadTemplate($viewName, $headerData = "",
$viewData="", $footerData=""){
$headerData["userId"] = (is_numeric($this->CI->session->userdata("userId")))
? $this->CI->session->userdata("userId") : null;
$this->CI->load->view('header/header', $headerData);
$this->CI->load->view($viewName, $viewData);
$this->CI->load->view('footer/footer', $footerData);
}
}
// 模板类以进一步的代码结束
// Login.php that extends template class
class Login extends Template {
public function Login() {
parent :: __construct();
}
public function getUserDetails(){
$userDetails = $this->loadTemplate("myDataNeedToshow");
}
}