我是使用CodeIgniter框架的初學者。以前,我學過Laravel。而我的問題是我想在Laravel製作像Blade這樣的動態模板。所以,在每一頁我只加載只有該頁面需要的樣式和腳本。CodeIgniter中的部分視圖
以下是我使用CodeIgniter創建的代碼,因此可以動態加載自定義樣式和自定義腳本。
的template.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
// <hmtl>
$this->load->view($header);
if(isset($style))
$this->load->view($style);
// <body>
$this->load->view($navbar);
if(isset($sidebar))
$this->load->view($sidebar);
$this->load->view($content);
$this->load->view($footer);
// </body>
if(isset($script))
$this->load->view($script);
// </html>
和我的控制器
public function index()
{
$data = [
'title' => 'Home',
'header' => 'partials/_header',
'navbar' => 'partials/_navbar',
'content' => 'guest/public',
'footer' => 'partials/_footer'
];
$this->load->view('template', $data);
}
也許你有更好的想法,因爲我堅持了下來。在Laravel很容易,因爲有@yield
和@section
。
來自你們的任何想法,都會對我很有幫助,謝謝。