thinkphp 跨控制器呼叫其他模組的方法

2021-08-27 16:20:49 字數 1250 閱讀 6838

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

$hello=new\admin\common\fun\hello();

$hello->hehe();

呼叫其他地方的方法同理。

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

如呼叫common裡面的某個類的方法:

$hello=new\common\fun\hello();

$hello->hehe();

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

classgoodscontrollerextendscontroller

}

呼叫示範:

a('user');//跨控制器

a('admin/user');//跨模組

a('shop://admin/user');    //跨專案

如果還是不夠方便的話框架還提供了r()方法,例項化類並呼叫方法。

//user為控制器 number為方法

r('user/number');

r('admin/user/number');

r('shop://admin/user/number');

效果如下:

classgoodscontrollerextendscontroller

}

ThinkPHP 跨控制器呼叫

乙個控制器在執行的時候,可以例項化另外乙個控制,並通過物件訪問其指定方法。跨控制器呼叫可以節省我們 的工作量 例如 有10 個頁面,都要現實指定的資料資訊顯示。比如我們 的 會員數目有 200萬 這個資訊需要在 10個頁面都顯示 這個資料是通過usercontroller.class.php 裡邊額...

ThinkPHP跨控制器呼叫方法

跨控制器呼叫方法 1.先造物件,再呼叫裡面的方法 sc new home controller indexcontroller 用絕對路徑找 echo sc shuchu 2.sc new indexcontroller 用相對路徑 echo sc shuchu 還可以使用thingkphp中的快捷...

ThinkPHP跨控制器呼叫方法

跨控制器呼叫方法 1.先造物件,再呼叫裡面的方法 sc new home controller indexcontroller 用絕對路徑找 echo sc shuchu 2.sc new indexcontroller 用相對路徑 echo sc shuchu 還可以使用thingkphp中的快捷...