任何人都可以告訴我如何在codeigniter中實現我的整個項目的默認模板/佈局?如何在codeigniter中獲取整個項目的默認模板/佈局?
的一種方式,我發現是Templating with Code Igniter (CI Forums)
有沒有其他辦法?任何人都可以發佈完整的示例代碼
任何人都可以告訴我如何在codeigniter中實現我的整個項目的默認模板/佈局?如何在codeigniter中獲取整個項目的默認模板/佈局?
的一種方式,我發現是Templating with Code Igniter (CI Forums)
有沒有其他辦法?任何人都可以發佈完整的示例代碼
製作一個佈局視圖。有些事情是這樣的:
<html>
<head>
<title>My awesome site</title>
</head>
<body>
<?= $this->load->view('shared/header') ?>
<?= $this->load->view($partial) ?>
<?= $this->load->view('shared/footer') ?>
</body>
</html>
然後在你的控制器做到這一點:
$this->data['partial'] = 'pages/index';
$this->load->view('layout/layout', $this->data);
如果你有一個MY_Controller文件,你可以創建有一個方法:在控制器
function load_view($partial)
{
$this->data['partial'] = $partial;
$this->load->view('layout/layout', $this->data);
}
那麼這繼承自MY_Controller,您可以使用:
$this->load_view('pages/index'); // pages/index will be loaded in the layout
我知道其中的一種方法是爲您的網站/項目創建頁眉和頁腳視圖。
application/views/template/header.php
application/views/template/footer.php
然後你有你的其他頁面如何安排你想要的。
application/views/users/login.php
在你的控制,你會做這樣的事情
<?php
class Blah extends CI_Controller
{
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->view('template/header');
$this->load->view('users/login');
$this->load->view('template/footer');
}
}
還有一個有用的小模板庫我偶然發現,使這個就更簡單了。但我覺得它不像輸入另一種方式那麼靈活。
http://maestric.com/doc/php/codeigniter_template
編輯:: 我應該給予一些示例代碼爲模板,在這裏你去
的header.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Lovely Title</title>
</head>
<body>
<h1>Check This Out!!1!</h1>
<div class="container">
footer.php
</div>
</body>
</html>
一個建議,自己嘗試,然後發佈任何問題,如果沒有任何嘗試的OP – Hailwood 2012-04-14 03:04:56