引言:
$this->load->view('header'); 那么在视图header里面再来一个$this->load->view('menu');
显然这个会产生错误,以下是解决方案~~
$this->load->view('header'); 那么在视图header里面再来一个$this->load->view('menu');
显然这个会产生错误,以下是解决方案~~
A lot of new CodeIgniter users have at one point asked, "How to load a view within another View?"
To load a view within another view . We can also use the same method we used in the controller to load the "primary" view.
<?php $this->load->view('header');?>
<div>
<p>This is the content</p>
</div>
<?php $this->load->view('footer');?>
Some coders might desire not to put $this->load->view() in the view . An alternative is to create a helper for loading views.
// load_view_helper.php
if ( ! function_exists('load_view'))
{
function load_view($view, $vars = '', $return = FALSE)
{
$CI =& get_instance();
return $CI->load->view($view, $vars, $return);
}
}
Add this to the helper array:
$autoload['helper'] = array('load_view');
And you're all set! To use:
<?php load_view('header');?>
<div>
<p>This is the content</p>
</div>
<?php load_view('footer');?>
There are still tons of alternatives out there. One that is recommended is using Colin William's Template Library . Our example is one of the simplest.
本文介绍如何在CodeIgniter框架中实现一个视图加载另一个视图的功能,并提供了一个简单的辅助函数来简化这一过程。此外,还提到了使用Colin Williams的模板库作为另一种推荐方案。
3264

被折叠的 条评论
为什么被折叠?



