[英]Codeigniter best way to handle controller calling views
我只是想知道這是否是添加碎片視圖的好方法。
可以說“ header.php”是這樣的
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap Admin Theme v3</title>
some links..
</head>
</html>
那么“ body.php”就是這樣
<!DOCTYPE html>
<html>
<body>
lots of stuff..
</body>
</html>
最后是“ scripts.php”
<!DOCTYPE html>
<html>
<body>
some scripts..
</body>
</html>
然后在我的“ MyController.php”中
$this->load->view('header');
$this->load->view('body');
$this->load->view('scripts');
我發現最好的方法是創建一個默認視圖。
views > default_view.php
views > includes > header_view.php
views > includes > footer_view.php
views > information > contact_view.php
在那個觀點上
<?php
$this->load->view('includes/header_view');
$this->load->view($content_page);
$this->load->view('includes/footer_view');
?>
然后,在控制器上以這種方式加載視圖時,您不必一直加載頁眉和頁腳視圖。
文件名:Example.php
<?php
class Example extends CI_Controller {
public function index() {
// Add any other variables
$data['content_page'] = 'information/contact_view'; // This will be your content page example
$this->load->view('default_view', $data);
}
}
有太多多余的標簽,例如<html>
, <body>
嘗試將其分開
header.php
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap Admin Theme v3</title>
some links..
</head>
<body>
body.php
lots of stuff..
scripts.php或footer.php
some scripts..
</body>
</html>
這不是好方法。 除非在某些情況下(例如使用框架),否則文檔應僅具有一個聲明和一對打開/關閉的html標簽。 可能是這樣的:
header.php
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap Admin Theme v3</title>
some links..
</head>
<body>
some_page.php
<div class="container">
<div class="row">
//some stuff and forms here
</div>
</div>
footer.php
<div class="footer">
//©2016
</div>
</body>
</html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.