如安在Cl结构视图中加载视图?
本文实例叙述了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"> <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结构的PHP程序设计有所协助。
本文地址:http://www.anyuan2002.com/bcdm/91512.html