<?php
namespace app\index\controller;
use app\index\facade\Test;
class Demo2
{
public function index($name='ThinkPHP')
{
//$test=new \app\index\common\Test();
//return $test->hello($name);
/**
*如果想静态调用一个动态方法,需要给当前的类绑定一个静态代理的类
*如果没有在静态代理类中显示指定要绑定的类名,就需要动态显示绑定一下
*\think\Facade::bind()
*/
\think\Facade::bind('app\index\facade\Test','app\index\common\Test');
return Test::hello('peer');
}
}
<?php
namespace app\index\common;
class Test
{
public function hello($name){
return 'hello '.$name;
}
}
<?php
namespace app\index\facade;
class Test extends \think\Facade
{
/*
protected static function getFacadeClass()
{
return 'app\index\common\Test';
}
*/
}