我有一个名为landingpage.php的 Controller
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class LandingPage extends CI_Controller {
public function index()
{
/*header*/ $head = $this->load->view('header_meta', '', true);
$this->load->view('index', array('head' => $head));
/*guts*/ $guts = $this->load->view('Landing_Guts', '', true);
$this->load->view('index', array('guts' => $guts));
/*footer*/ $foot = $this->load->view('footerLanding', '', true);
$this->load->view('index', array('foot' => $foot));
}
}
页脚着陆:
<div id="redStripe_a"> </div>
</div><!--/container_a-->
<div id="footer_a">
<ul id="footer">
<li><a href="#">About</a></li>
<li><a href="#">Blog</a></li>
<li><a href="#">Contact</a></li>
<li><a href="#">Press</a></li>
<li><a href="#">Terms</a></li>
<li><a href="#">Privacy</a></li>
<li><a href="#">Feedback</a></li>
<li><a href="#">Jobs</a></li>
<span class="red" style="float:right;font-size:0.8em;">© 2012 Co,Inc.</div></span>
</ul><!--/footer :: ul-->
<div id="clearB"> </div>
</div><!--/footer_a-->
index.php( View )
<?php echo $head; ?>
<body>
<?php echo $guts; ?>
</body>
<?php echo $foot; ?>
加载页面时,我在页面上收到以下错误...但代码已放入 View 中,因为如果我查看源代码
,我会看到它包含在 View 的源代码中.
最佳答案
我想您可能想阅读一些有关如何正确加载 View 的内容。
public function index(){
// Load each view ONCE
$data = array(
'head' => $this->load->view('header_meta', '', true),
'guts' => $this->load->view('Landing_Guts', '', true),
'foot' => $this->load->view('footerLanding', '', true)
);
// Load index view ONCE, passing variables in data array
$this->load->view('index', $data);
}
代码未经测试,但这是总体思路。另外,我建议您的 View 文件坚持使用单一命名约定。
关于php - 显示单页 Code Igniter MVC 的多个 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9649578/