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");
}
}
是否有除了用戶指南模板引擎一個簡單的教程?我很難理解如何簡單地使用它。 – Rasteril
@Rasteril:檢查這個回購https://github.com/mrsrinivas/ci_template – mrsrinivas