CI(CodeIgniter)框架视图中加载视图的方法

所属分类: 网络编程 / PHP编程 阅读数: 1160
收藏 0 赞 0 分享

本文实例讲述了CI(CodeIgniter)框架视图中加载视图的方法。分享给大家供大家参考,具体如下:

CI做为php的一个轻量级框架,其自身具备很多优点,在此我重点想说的是视图中加载视图。

1:在Application\config\database.php文件中设置好CodeIgniter 数据库变量之后,紧接着在Application\config\config.php文件中设置基础 URL。例如我的基础 URL 是:http://localhost/codeigniter/

2:接下来创建默认的控制器与视图,创建控制器的目录为:application\controllers\ 文件夹内,创建一个名为 student.php 的控制器。并在 application\config\routes.php 内将其设置为默认控制器。

Controller->student.php

class Student extends CI_controller{
  public function __construct(){
    parent::__construct();
  }
  public function index(){
    $date['title']="Classroom:Home Page";
    $date['headline']="Welcome to the Classroom Management System";
    $date['include']="Student_index";
    $this->load->view('template',$date);
  }
}

views->template.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title><?php echo $title;?></title>
</head>
<body>
<h1><?php echo $headline;?></h1>
<?php $this->load->view($include);?>
</body>
</html>

view->student_index.php

Congratulations.Your initial setup is complate!

如果你访问:http://localhost/CodeIgniter/index.php/student/index

the result will output:

Welcome to the Classroom Management System
Congratulations.Your initial setup is complate!

更多关于CodeIgniter相关内容感兴趣的读者可查看本站专题:《codeigniter入门教程》、《CI(CodeIgniter)框架进阶教程》、《php优秀开发框架总结》、《ThinkPHP入门教程》、《ThinkPHP常用方法总结》、《Zend FrameWork框架入门教程》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总

希望本文所述对大家基于CodeIgniter框架的PHP程序设计有所帮助。

更多精彩内容其他人还在看

用php实现像JSP,ASP里Application那样的全局变量

用php实现像JSP,ASP里Application那样的全局变量
收藏 0 赞 0 分享

自动分页的不完整解决方案

自动分页的不完整解决方案
收藏 0 赞 0 分享

FCKeditor的安装(PHP)

FCKeditor的安装(PHP)
收藏 0 赞 0 分享

mysql5详细安装教程

mysql5详细安装教程
收藏 0 赞 0 分享

isset和empty的区别

isset和empty的区别
收藏 0 赞 0 分享

php5.2时间相差8小时

php5.2时间相差8小时
收藏 0 赞 0 分享

安装APACHE

安装APACHE
收藏 0 赞 0 分享

PHP5 安装方法

PHP5 安装方法
收藏 0 赞 0 分享

PHP has encountered an Access Violation

PHP has encountered an Access Violation
收藏 0 赞 0 分享

MYSQL环境变量设置方法

本文介绍了mysql数据库中环境变量的设置方法,如何设置mysql数据库的环境变量,有需要的朋友参考下
收藏 0 赞 0 分享
查看更多