温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

CodeIgniter框架视图中如何加载视图

发布时间:2021-07-30 14:35:51 来源:亿速云 阅读:122 作者:小新 栏目:开发技术

这篇文章将为大家详细讲解有关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>
<h2><?php echo $headline;?></h2>
<?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框架视图中如何加载视图”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI