thinkphp5.1学习过程五——静态代理

给你一囗甜甜゛ 提交于 2019-12-04 23:38:52
<?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';
  }
  */
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!