codeigniter view 试图里再引入view视图

引言:

$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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值