thinkphp5跨控制器调用
来源:WDPHP技术站
时间:2021年01月29日
浏览次数:509次
同模块
方法一:使用命名空间
//调用index模块user控制器中的index方法 $model = new \app\index\controller\User; echo $model->index();
方法二:
//先引入 use app\index\controller\User; $model = new User; echo $model->index();
方法三:
//使用系统方法 $model = controller('User'); echo $model->index();
其他模块控
方法一,前台index模块调用后台admin下面的控制器方法
//使用命名空间 $model = new \app\admin\controller\Index; echo $model->index();
方法二:
//使用引入 use \app\admin\controller\Index as AdminIndex; //注意控制器名重复要改别名 $model = new AdminIndex(); echo $model->index();
方法三:
//系统方法调用 $model = controller('admin/Index'); echo $model->index();
同控制器的其他方法
//fangfa方法调用test方法 public function fangfa(){ //方法一: echo $this->test(); //方法二: echo self::test(); //方法三: echo Index::test();//Index控制器 //方法四: echo action(' test'); }
其他控制器方法与其他模块方法
public function fangfa(){ //调用同控制器的index方法 echo action('index'); //调用其他控制器index方法 echo action('User/index'); //调用其他模块下的index方法 echo action('admin/Index/index'); }
相关文章:
- [PHP编程]PHP 随机生成n条手机号
- [PHP编程]Thinkphp header获取参数失败的原因
- [PHP编程]thinkphp5跨控制器调用
- [PHP编程]tp5中用find_in_set thinkphp5中find_in_set的使用方法
- [PHP编程]ThinkPHP5.1使用redis缓存
- [PHP编程]阿里云短信平台Alibaba Cloud SDK for PHP使用教程
- [PHP编程]ThinkPHP5中saveAll和insertAll的用法
- [PHP编程]ThinkPHP5事务回滚
- [PHP编程]tp5.1 使用Composer安装验证码扩展包
- [PHP编程]php将数组或对象原样写入或保存到文件有三种方法
相关推荐:
- [PHP编程]PHP 随机生成n条手机号
- [PHP编程]Thinkphp header获取参数失败的原因
- [PHP编程]thinkphp5跨控制器调用
- [PHP编程]tp5中用find_in_set thinkphp5中find_in_set的使用方法
- [PHP编程]ThinkPHP5.1使用redis缓存
- [PHP编程]阿里云短信平台Alibaba Cloud SDK for PHP使用教程
- [PHP编程]ThinkPHP5中saveAll和insertAll的用法
- [PHP编程]ThinkPHP5事务回滚
- [PHP编程]tp5.1 使用Composer安装验证码扩展包
- [PHP编程]php将数组或对象原样写入或保存到文件有三种方法
栏目分类
最新文章
热门文章