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方法
}
}