当前位置:首页 > PHP教程 > PHP常见问题

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

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

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

1:在applicationconfigdatabase.php文件中设置好codeigniter 数据库变量之后,紧接着在applicationconfigconfig.php文件中设置基础 url。例如我的基础 url 是:http://localhost/codeigniter/

2:接下来创建默认的控制器与视图,创建控制器的目录为:applicationcontrollers 文件夹内,创建一个名为 student.php 的控制器。并在 applicationconfigroutes.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程序设计有所帮助。



【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!