打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
codeigniter view 试图里再引入view视图
2009-12-12

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代码
  1. <?php $this->load->view('header');?>
  2. <div>
  3. <p>This is the content</p>
  4. </div>
  5. <?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.

Php代码
  1. // load_view_helper.php
  2. if ( ! function_exists('load_view'))
  3. {
  4. function load_view($view, $vars = '', $return = FALSE)
  5. {
  6. $CI =& get_instance();
  7. return $CI->load->view($view, $vars, $return);
  8. }
  9. }

Add this to the helper array:

Php代码
  1. $autoload['helper'] = array('load_view');

And you're all set! To use:

Php代码
  1. <?php load_view('header');?>
  2. <div>
  3. <p>This is the content</p>
  4. </div>
  5. <?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.

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
PHP简单导出Excel表格
当Zend Framework的Partial View Helper遇上Smarty
Razor代码复用
php 下载远程图片 的几种方法
as3 和PHP 后台交互 大全
Android 下拉刷新框架实现
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服