我爲我的web項目使用codeigniter php框架。我的問題是如何爲css,js和圖像等資源設置多個模板佈局和基本路徑?我想設置前端,登錄和後端佈局。所以我需要設置3個佈局。Codeigniter - 如何設置多個模板佈局和資產(CSS,JS和圖像)?
我的項目結構
這些是我的項目的樣本代碼。
MY_Controller.php
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class My_Controller extends CI_Controller {
protected $layout = 'admin';
protected $stylesheets = array(
'app.css'
);
protected $javascripts = array(
'app.js'
);
protected function render($content) {
$view_data = array(
'content' => $content,
'stylesheets' => $this->get_stylesheets(),
'javascripts' => $this->get_javascripts()
);
$this->load->view($this->layout,$view_data);
}
protected function get_stylesheets() {
return $this->stylesheets;
}
protected function get_javascripts() {
return $this->javascripts;
}
}
Home.php
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class Home extends My_Controller {
public function index() {
$content = $this->load->view('home/index',null,true);
$this->render($content);
}
}
?>
我在互聯網上找到此鏈接,但不適合我的項目。 http://williamsconcepts.com/ci/codeigniter/libraries/template/reference.html
我使用williamsconcepts模板,它適用於我。爲什麼不適合你?就是想? – TigerTiger