是的。
创建一个在文件夹中调用的文件。template.php
views
内容:template.php
$this->load->view('templates/header');
$this->load->view($v);
$this->load->view('templates/footer');
然后,从控制器中,您可以执行如下操作:
$d['v'] = 'body';
$this->load->view('template', $d);
这实际上是我个人如何加载我所有观点的非常简单的版本。如果你把这个想法发挥到极致,你可以做一些有趣的模块化布局:
请考虑是否创建一个名为包含单行的视图:init.php
$this->load->view('html');
现在创建包含以下内容的视图:html.php
<!DOCTYPE html>
<html lang="en">
<? $this->load->view('head'); ?>
<? $this->load->view('body'); ?>
</html>
现在创建一个包含以下内容的视图:head.php
<head>
<title><?= $title;?></title>
<base href="<?= site_url();?>">
<link rel="shortcut icon" href='favicon.ico'>
<script type='text/javascript'>//Put global scripts here...</script>
<!-- ETC ETC... DO A BUNCH OF OTHER <HEAD> STUFF... -->
</head>
以及包含以下内容的视图:body.php
<body>
<div id="mainWrap">
<? $this->load->view('header'); ?>
<? //FINALLY LOAD THE VIEW!!! ?>
<? $this->load->view($v); ?>
<? $this->load->view('footer'); ?>
</div>
</body>
并根据需要创建和查看。header.php
footer.php
现在,当您从控制器调用init时,所有繁重的工作都已完成,您的视图将被包裹在里面和标签中,您的页眉和页脚将被加载进去。<html>
<body>
$d['v'] = 'fooview'
$this->load->view('init', $d);