thinkphp基礎入門(2),thinkphp基礎入門_PHP教程

來源:互聯網
上載者:User

thinkphp基礎入門(2),thinkphp基礎入門


第一節介紹了thinkphp基本路徑問題,第二節將介紹thinkphp的常見用法(M層跟V層)

我們先在Controller層建立個IndexController.class.php(建立檔案的格式為xxxController.class.php,建議首字母大寫)其他寫法,架構將不識別為控制器檔案

建立個index函數

php namespace Home\Controller; use Think\Controller; class IndexController extends Controller {          public function index(){         $this->assign('variable',"輸出變數到模板中"); //assign的作用是將控制器的變數輸出到V層        $this->display();//assign完後一定要display一下才能輸出到模板中     }

然後我們在View檔案夾中新增個Index檔案夾(名稱要與控制器名稱一致,比如AaaController的控制器就要建立個Aaa檔案夾),在Index裡面建立個index.html檔案(這名字要與Index控制器中display的函數名一致),輸入以下代碼:
DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Documenttitle>head><body>    {$variable}body>html>

 {$xxx} 這可以輸出controller中assign的變數,這時我們在url輸入http://localhost/你的檔案夾名/index.php?m=Home&c=Index&a=index,將會出現“輸出變數到模板”這幾個字,這樣就實現了輸出變數到模板中。這個非常常用!!

然後第二個常用的地方就是U函數,I函數 這裡不多說了 詳見api文檔

沒有display函數的都是不會渲染到模板上的,可以用於操作邏輯,然後如果ajax中請求一個地址,這個請求地址為控制器某個函數(體現在url的a參數上),其他動作跟純生的php編程差不多了。
 
 

http://www.bkjia.com/PHPjc/1110978.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1110978.htmlTechArticlethinkphp基礎入門(2),thinkphp基礎入門 第一節介紹了thinkphp基本路徑問題,第二節將介紹thinkphp的常見用法(M層跟V層) 我們先在Controller層建立...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.