thinkphp5.1跨控制器调用方法--示例

 

<?php

namespace app\index\controller;

use app\index\model\Profile;
use think\Controller;
use think\facade\Url;
use think\Request;


class Test extends Controller
{
        public function fenCeng()
    {
        //方法1:跨模块访问控制器
//        $event = \think\facade\App::controller('app/Index');
        //使用助手函数更简单
//        $event = controller('app/Index');

        //方法2:不跨模块调用别的目录下的类的方法
        $e2 = \think\facade\App::controller('Blog','test');
        //使用助手函数更简单
        $e2 = controller('Blog','test');
        $res = $e2->kua();

//        $res = $event->index();
        var_dump($res);
    }
}

<?php

namespace app\index\test;

class Blog
{
    public function kua()
    {
        return '跨控制器调用示范';
    }
}

<?php

namespace app\app\controller;

use think\Controller;

class Index extends Controller
{
    public function index()
    {
        return '入口文件绑定到模块app';
    }
}

猜你喜欢

转载自blog.csdn.net/shj_php/article/details/88287210