当前位置:首页 > PHP教程 > PHP常见问题

thinkphp3.2实现跨控制器调用其他模块的方法

本文实例讲述了thinkphp3.2实现跨控制器调用其他模块的方法。分享给大家供大家参考,具体如下:

thinphp中前台后台都有互相调用方法,这样可以省去重复内容。

$hello = new admincommonfunhello(); $hello->hehe();

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

如果是在同控制器里模块名可以省略。

如调用common里面的某个类的方法:

$hello = new commonfunhello(); $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方法 } }

更多关于thinkphp相关内容感兴趣的读者可查看本站专题:《thinkphp入门教程》、《thinkphp模板操作技巧总结》、《thinkphp常用方法总结》、《codeigniter入门教程》、《ci(codeigniter)框架进阶教程》、《zend framework框架入门教程》、《smarty模板入门基础教程》及《php模板技术总结》。

希望本文所述对大家基于thinkphp框架的php程序设计有所帮助。



【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!