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!
更多关于CodeIgniter相关专题:《codeigniter入门教程》、《CI(CodeIgniter)框架进阶教程》、《php优秀开发框架总结》、《Zend FrameWork框架入门教程》
以上就是本文PHP -- CI(CodeIgniter)框架在视图中加载视图的方法的全部内容,希望本文所述对大家基于CodeIgniter框架的PHP程序设计有所帮助。
相关推荐
深度学习 -- 损失函数
深度残差网络(Deep Residual Networks (ResNets))
深度学习 -- 激活函数
神经网络训练 -- 调整学习速率
生成对抗网络(GAN)改进与发展
生成对抗网络(GAN)优点与缺点
生成对抗网络(GAN)的训练
生成对抗网络(GAN)基本原理
生成模型与判别模型