引言:
$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.
分享到:
相关推荐
视图view-ci(codeigniter)php框架_.docx
视图View-CI(codeigniter)PHP框架__1.docx
Codeigniter视图模板一个简单的布局管理,设置一次即可使用多次,并且可以在控制器上一行完成。要求Codeigniter 3.xx安装下载,然后复制并粘贴到application/library目录中。配置在自动加载库application/config/...
public function add_package_path($path, $view_cascade=TRUE) { $path = rtrim($path, '/').'/'; array_unshift($this->_ci_library_paths, $path); array_unshift($this->_ci_model_paths, $path); array_unshift...
本文实例讲述了CI(CodeIgniter)框架视图中加载视图的方法。分享给大家供大家参考,具体如下: CI做为php的一个轻量级框架,其自身具备很多优点,在此我重点想说的是视图中加载视图。 1:在Application\config\...
codeigniter框架中直接调用视图的函数,可以直接在模板或者控制器中使用。
通常在使用codeigniter的时候经常使用这样的方式载入: $this->load->view('about', $data); 通过这个类库,可以将一个视图载入到这个模板中: $this->template->load('template', 'about', $data); 这里将...
CodeIgniter 验证码 一个易于使用的 CodeIgniter 库,可与 reCAPTCHA 2.0 版(又名 NO CAPTCHA reCAPTCHA)配合使用。 安装 将文件复制到各自的位置。 ##Configuration 打开“ application/config/recaptcha.php ”...
Dengan menggunakan framework 3.x, generator ini bisa membuat sebuah Controller, Model, view, dan migration melalui command prompt. Cara menggunakannya extract file generator-master.zip kemudian ...
关于 这是一个非常简单的 RESTful API,没有令牌认证。 数据信息为JSON ...$ route [ 'api/v1/product/(:num)' ][ 'get' ] = 'api/v1/product/view/$1' ; $ route [ 'api/v1/product' ][ 'post' ] =
该书通常会涵盖以下内容...视图和模板引擎: 讨论如何设计和实现视图层,以及如何使用模板引擎来管理和渲染视图。 控制器和业务逻辑: 介绍控制器层的作用和功能,以及如何在控制器中实现业务逻辑、处理用户输入等。
视图 (View) 是展示给用户的信息。一个视图通常是一个网页。 控制器 (Controller) 是模型、视图以及其他任何处理 HTTP 请求所必须的资源之间的中介,并生成网页。 举例 比如一批统计数据你可以分别用柱状图、饼图来...
CodeIgniter-PDF-Generator-Library 已弃用:正在为此包寻找新的维护者。 如果有兴趣,请打开一个问题。 使用这个基于 domPDF 的易于使用的库在 CodeIgniter 中生成 PDF。安装将 pdf.php 库放入您的库目录中。 从...
模板库:处理masterview和masterview中的视图 Ajax请求和响应库:提供快速将所有内容都进行Ajax的方法 附加组件 加载项是一些有用的库和插件的自定义构建。 它们不包含在项目中,但是已经具有一种快速的安装技巧,...
该库查找与控制器和视图同名的 css/js 文件,并加载这些文件(如果存在): - controller.css - controller_view.css - controller.js - controller_view.js
PHP的MVC编程思想目前已经被...V:View 视图,负责调用Model调取数据,再调用模板,展示出最终效果。 C:Controller 控制器,程序的入口,决定改调用哪个View,并告诉View该做什么。 如此说来,程序的执行顺序是C-V-M
·类视图:(View->Window->Class View)包含所有打开的文件中的代码元素(类、函数和变量)。您可以轻松地浏览并找到您的项目在其中选择元素的所有声明。 ·在浏览器中预览 ·项目管理 ·增量查找 ·All standard ...