CI(CodeIgniter)框架視圖中加載視圖的方法
本文實例講述了CI(CodeIgniter)框架視圖中加載視圖的方法。分享給大家供大家參考,具體如下:
CI做為php的一個輕量級框架,其自身具備很多優(yōu)點,在此我重點想說的是視圖中加載視圖。
1:在Application\config\database.php文件中設置好CodeIgniter 數(shù)據(jù)庫變量之后,緊接著在Application\config\config.php文件中設置基礎 URL。例如我的基礎 URL 是:http://localhost/codeigniter/
2:接下來創(chuàng)建默認的控制器與視圖,創(chuàng)建控制器的目錄為:application\controllers\ 文件夾內,創(chuàng)建一個名為 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相關內容感興趣的讀者可查看本站專題:《codeigniter入門教程》、《CI(CodeIgniter)框架進階教程》、《php優(yōu)秀開發(fā)框架總結》、《ThinkPHP入門教程》、《ThinkPHP常用方法總結》、《Zend FrameWork框架入門教程》、《php面向對象程序設計入門教程》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家基于CodeIgniter框架的PHP程序設計有所幫助。
相關文章
php利用fsockopen GET/POST提交表單及上傳文件
這篇文章主要為大家詳細介紹了php利用fsockopen GET/POST提交表單及上傳文件,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-05-05PHP使用SOAP調用.net的WebService數(shù)據(jù)
需要和一個.net系統(tǒng)進行數(shù)據(jù)交換,對方提供了一個WebService接口,使用PHP如何調用這個數(shù)據(jù)呢,下面就看看使用SOAP調用的方法吧2013-11-11PHP解密支付寶小程序的加密數(shù)據(jù)、手機號的示例代碼
這篇文章主要介紹了PHP解密支付寶小程序的加密數(shù)據(jù)、手機號的示例代碼,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-02-02詳解thinkphp+redis+隊列的實現(xiàn)代碼
本篇文章主要介紹了thinkphp+redis+隊列的實現(xiàn)代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-08-08