Facade静态代理
< ? php namespace app\index\controller ; //use \app\facade\Test; class Demo2 { public function index ( $name = 'ThinkPHP' ) { //对象方式访问hello方法 // $test = new \app\common\Test; // return $test->hello($name); /** * 如果想静态调用一个动态方法,需要给当前的类绑定一个静态代理的类 *如果没有在静态代理类中显示指定要绑定的类名,就需要动态显示绑定一下 * \think\Facade::bind() */ \think\Facade : : bind ( 'app\facade\Test' , '\app\common\Test' ) ; // 实际上访问路径为 \app\facade\Test::hello('Peter Zhu'); return Test : : hello ( 'Peter Zhu' ) ; } } 名字建议和代理类相同 < ? php namespace app\facade ; //app\facade\Test 代理了 app\common\Test class Test extends \ think \ Facade { //代理app\common