• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

关于CI框架视图中加载视图的方法

php 搞代码 4年前 (2022-01-22) 15次浏览 已收录 0个评论

这篇文章主要介绍了CI(CodeIgniter)框架视图中加载视图的方法,结合实例形式分析了CodeIgniter框架视图加载相关操作技巧,需要的朋友可以参考下

本文实例讲述了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">&lt<b style="color:transparent">(、本文来源gao@!dai!ma.com搞$$代^@码网*</b><i>搞gaodaima代码</i>;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 SystemCongratulations.Your initial setup is complate!

以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请随时关注我们网站!

相关推荐:

关于CI框架操作redis的方法

CI框架的公共模型类定义与用法

以上就是关于CI框架视图中加载视图的方法的详细内容,更多请关注搞代码gaodaima其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:关于CI框架视图中加载视图的方法

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址