thinkphp6如何引入extend第三方类库
2022-11-24 11:10:29
211
{{single.collect_count}}

thinkphp6如何引入extend第三方类库?vendor的是通过composer的方法进行自动引入到第三方扩展库vendor目录里的,extend是通过手动的方法直接把第三方扩展库或者自己写的封装库直接引入到extend目录里。

下面我们就用一个详细案例讲解一下,如何引用extend下的第三方类库。

1.在extend目录下新建类文件,比如:extend\share\Jssdk.php

2. Jssdk.php里面的代码如下。

namespace share;

class Jssdk

{

private $appId;

private $appSecret;

public function __construct($appId, $appSecret)

{

$this->appId = $appId;

$this->appSecret = $appSecret;

}

public function index()

{

echo "this is a  test";

}

}

3.在控制器中试用,引入命名空间 use share\Jssdk;

4.在控制器action中,实例化对象

public function index()

{

$b=new Jssdk();

echo $b->index(); // 输出 this is a test

}

回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}