首页 > PHP教程 > php开发知识文章

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

本文主要介绍了PHP -- CI(CodeIgniter)框架在视图中加载视图的方法。分享给大家供大家参考,欢迎大家的学习。

CI是php的一个轻量级框架,有很多优点,本文介绍在视图中加载视图的方法。

1.在Application/config/database.php文件中配置好CodeIgniter 数据库变量之后,在Application/config/config.php文件中配置基础 URL。如基础 URL 是:http://localhost/codeigniter/

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

Controller->user.php文件

class User extends CI_controller
{
public function __construct()
{
parent::__construct();
}

public function index()
{
$date['title'] = "Classroom:Home Page";
$date['headline'] = "Welcome to the Class";
$date['include'] = "user_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->user_index.php文件

Congratulations.Your initial setup is complate!

访问:http://localhost/CodeIgniter/index.php/user/index

输出:

Welcome to the Class Congratulations.Your initial setup is complate!

PHP -- CodeIgniter框架的基本用法

更多关于CodeIgniter相关专题:《codeigniter入门教程》、《CI(CodeIgniter)框架进阶教程》、《php优秀开发框架总结》、《Zend FrameWork框架入门教程

以上就是本文PHP -- CI(CodeIgniter)框架在视图中加载视图的方法的全部内容,希望本文所述对大家基于CodeIgniter框架的PHP程序设计有所帮助。

关闭
感谢您的支持,我会继续努力!
扫码打赏,建议金额1-10元


提醒:打赏金额将直接进入对方账号,无法退款,请您谨慎操作。