ThinkPHP 架構模型

來源:互聯網
上載者:User

標籤:

本文和大家分享的主要是ThinkPHP 架構模型相關內容,一起來看看吧,希望對大家學習php有所協助。 1 在MainController.class.php 控制器中有一個test的方法,同時還有一個deng的方法,我想在test方法中使用deng方法 表示為 <?phpnamespace Home\Controller;use Think\Controller;class MainController extends controller{ public function test() { $this->deng(); } 2 在MainController.class.php 控制器中有一個test的方法,在同一個模板下還有一個名為IndexController.class.php的控制器,其中有一個index方法,我想在test方法中使用index方法 表示為: <?phpnamespace Home\Controller;use Think\Controller;class MainController extends controller{ public function test() { //跨控制器調用方法 $index=new IndexController(); $index->index(); $index=A("Index"); $index->index(); R("Index/index"); } 上述是三種不同的調用方法 3 在Home檔案夾下的MainController.class.php 控制器中有一個test的方法,在不同的模板Admin檔案夾下還有一個名為TextController.class.php的控制器,其中有一個aa方法,我想在test方法中使用aa方法 表示為: <?phpnamespace Home\Controller;use Think\Controller;class MainController extends controller{ public function test() { //跨模組調用方法 $index=new \Admin\Controller\TextController(); $index->aa(); $index=A("Admin/Text"); $index->aa(); R("Admin/Text/aa"); } 4 使用模型來操作資料庫,用D調出來的是子類對象,如果用M(“nation”)調出來的是父類對象; 用select() 調出來的是所有對象,是一個二維數組,如果用find()調出來的是一條資料,比如 find("n001") $nation=D("nation");$arr=$nation->select(); var_dump($arr); 5 用where查詢語句 where(條件) $nation=D("nation"); $arr=$nation->where("code=’n005’ or code=’n003’")->select(); var_dump($arr) 查出來的是兩條資料 6 TABLE()可以用來切換資料表 我選用的是資料庫club中的表格cname來切換 $nation=D("nation");$arr=$nation->table("cname")->select(); var_dump("$arr"); 7 field(指定的資料庫的某一個欄位),查詢出來的只有這個欄位的資料 $nation=D("nation");$arr=$nation->field("code")->select(); var_dump($arr); 8 order() 是指把查詢的內容按照順序排列 $nation=D("nation");$arr=$nation->order("code desc")->select(); var_dump($arr); 9 limit() 分頁查詢 如果()內只有一個值,那麼意味著顯示多少條資料, 如果有兩個值(,)那麼意味著跳過多少條顯示多少條 $nation=D("nation");$arr=$nation->limit(6)->select(); var_dump($arr); 如果用的是page()分頁查詢 會更人性化 page(,)括弧裡面有兩個值,第一個值表示第幾頁,第二個值表示每頁顯示多少條 10 分組 group() 比如我要查car表中 按照brand分組 每一組有多少條資料 $nation=D("nation"); $arr=$nation->field("brand,count(*)")->table("car")->group("brand")->select(); var_dump($arr); 11 join  使兩個表聯絡起來 $login=D("login");$arr=$login->field("login.uid,login.pwd,cname.name")->join("cname on cname.code=login.code")->select(); var_dump($arr);


來源:部落格園

ThinkPHP 架構模型

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.