[CI框架02]視圖View使用

 按照前面的看到的歡迎頁面裏使用view的方式,咱們這裏php

在views目錄下建一個模版文件hello.php(默認是php後綴,你也能夠用其餘的如.html可是調用時須要帶全後綴如$this->load->view('hello.html').html

views/hello.php:框架

  
  
  
  
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
  2. <html xmlns="http://www.w3.org/1999/xhtml"> 
  3. <head> 
  4. <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
  5. <title>view</title> 
  6. </head> 
  7. <body> 
  8. hello,view! 
  9. </body> 
  10. </html> 

控制器裏代碼:ide

 

  
  
  
  
  1. function index() 
  2.     $this->load->view('hello'); 

測試http://127.0.0.1:82/dayup/ci2/index.php測試

hello,view!ui

如今看看若是給views傳變量數據。this

修改控制器的index方法以下:spa

 

  
  
  
  
  1. function index() 
  2.     $data=array
  3.         'title'=>'歡迎使用CI框架'
  4.         'hello'=>'hello,歡迎使用CI框架!' 
  5.     ); 
  6.     $this->load->view('hello',$data); 

修改模版文件:xml

 

  
  
  
  
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
  2. <html xmlns="http://www.w3.org/1999/xhtml"> 
  3. <head> 
  4. <meta http-equiv="content-type" content="text/html; charset=gbk" /> 
  5. <title><?=$title ?></title> 
  6. </head> 
  7. <body> 
  8. <?=$hello ?> 
  9. </body> 
  10. </html>
相關文章
相關標籤/搜索