我對使用CI還是比較陌生,但我一直在爲它構建模塊化模板系統,我想我已經掌握了它的基本原理。我的問題是,當我使用我的模板系統時,加載時間似乎是顯而易見的。我很好奇,如果這是常見的,或者如果我做錯了什麼。我知道頁面加載時間有很多變數,而且我的網站依賴於VPS,所以也可能是因爲我與誰共享資源的人都在吮吸他們。熟悉CI的人能否查看我的代碼並查看是否有任何事情可以在不犧牲模塊化結構的情況下加快加載時間?使用模板系統時Codeigniter的性能
感謝
routes.php文件
$route['default_controller'] = 'pages/load/home';
$route['test/(:any)'] = 'sandbox/load/$1';
$route['(:any)'] = 'pages/load/$1';
$route['404_override'] = '';
pages.php
class Pages extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('menulinks_model');
}
public function load($what = 'home'){// Default load
$array = array();
//Make sure content exists
if (!file_exists('application/views/content/'.$what.'.php')){
// Whoops, we don't have a page for that!
$page_content = "The page you are looking for does not exist (ERROR 404)";
}else {
//Get menu data
$array['menulinks'] = $this->menulinks_model->getAllMenuLinks();
//Get page content
$page_content = $this->load->view('content/'.$what,$array,TRUE);
}
//Build Page
$data = array();
$data['head'] = $this->load->view('templates/headplate',$array,TRUE);
$data['scripts'] = $this->load->view('templates/scriptplate',$array,TRUE);
$data['content'] = $page_content;
$data['footer'] = $this->load->view('templates/footplate',$array,TRUE);
//Render page
$this->load->view('templates/siteplate', $data);
}
模板是什麼樣的?那裏有很多繁重的工作或數據庫交互嗎?還可以看看內置的Profiler類,以幫助您找出發生放緩的位置http://ellislab.com/codeigniter/user-guide/general/profiling.html – Dormouse