thinkphp3.2實現跨控制器調用其他模組的方法

來源:互聯網
上載者:User
這篇文章主要介紹了thinkphp3.2實現跨控制器調用其他模組的方法,分析了thinkPHP跨模組、跨控制器調用方法的常見操作技巧,需要的朋友可以參考下

本文執行個體講述了thinkphp3.2實現跨控制器調用其他模組的方法。分享給大家供大家參考,具體如下:

thinphp中前台後台都有互相調用方法,這樣可以省去重複內容。

$hello = new \Admin\Common\Fun\hello();$hello->hehe();

調用其他地方的方法同理。

如果是在同控制器裡模組名可以省略。

如調用common裡面的某個類的方法:

$hello = new \Common\Fun\hello();$hello->hehe();

架構裡面提供了跨模組、誇控制器的 A() 方法

class GoodsController extends Controller{  function showlist(){    // 執行個體化User控制器與調用方法    $user = A('User');//通過快捷函數執行個體化控制器對象    echo $user->number();//調用number()方法  }}

調用示範:

A('User');  //跨控制器A('Admin/User');  //跨模組A('shop://Admin/User');  //跨項目

如果還是不夠方便的話架構還提供了R()方法,執行個體化類並調用方法。

//User為控制器 number為方法R('User/number');R('Admin/User/number');R('shop://Admin/User/number');

效果如下:

class GoodsController extends Controller{  function showlist(){    // 執行個體化User控制器與調用方法        A('User/number');//執行個體化user類並調用number方法  }}

聯繫我們

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