我对使用 CI 还是很陌生,但我一直在为它构建一个模块化模板系统,我想我已经掌握了它的基本知识。我的问题是,当我使用模板系统时,加载时间似乎很明显。我很好奇这是否常见,或者我做错了什么。我知道页面加载时间有很多变量,而且我的网站位于 VPS 上,因此也可能只是与我共享资源的人在吸食它们。精通 CI 的人是否可以查看我的代码,看看我是否可以做些什么来加快加载时间而不牺牲模块化结构?
谢谢
路由.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);
}