【发布时间】:2015-12-27 17:09:19
【问题描述】:
我正在为我的 Web 项目使用 codeigniter php 框架。我的问题是如何为css、js和图像等资产设置多个模板布局和基本路径?我想设置前端、登录和后端布局。所以我需要设置 3 个布局。
我的项目结构
这些是我的项目的示例代码。
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;
}
}
主页.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 模板,它对我来说效果很好。为什么不适合你??只是想知道?
标签: php codeigniter