首页 > 语言 > PHP > 正文

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

2024-05-04 23:55:53
字体:
来源:转载
供稿:网友

本文实例讲述了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方法  }}

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


注:相关教程知识阅读请移步到PHP教程频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选