zoukankan      html  css  js  c++  java
  • thinkphp3.2实现跨控制器调用其他模块的方法

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

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

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

      


    $Cron=D('Admin/Cron');
    echo $Cron->timeInput('kew');
    

      

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

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

    如调用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方法
      }
    }
    

      

  • 相关阅读:
    DAY-4 Linux基础及常用命令(1)
    DAY-3 计算机基础之网络
    DAY-2 计算机基础之操作系统
    DAY-1 计算机基础
    梅花作品欣赏
    简洁大气网址(国外)跟设计大学的案例很像
    animate css3 应用的借鉴,一个同事写的JS
    漂亮的素材
    几个不错的素材站
    正式开始我的技术生涯
  • 原文地址:https://www.cnblogs.com/microtiger/p/13181127.html
Copyright © 2011-2022 走看看