您的位置:首页 > 编程语言 > PHP开发

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

2019-11-20 18:05 1311 查看
<?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';
}
*/
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ThinkPHP