[英]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.