php - 在 yii2 控制器中使用 composer 包
问题描述
我已经使用composer安装了一个composer包,我还检查了包是否加载到index.php入口脚本中,这就是它的样子
<?php
// comment out the following two lines when deployed to production
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../vendor/yiisoft/yii2/Yii.php';
$config = require __DIR__ . '/../config/web.php';
(new yii\web\Application($config))->run();
我已经安装了这个包composer require php-http/curl-client typesense/typesense-php
,我在我的控制器中使用它
<?php
namespace app\controllers;
use Yii;
use yii\filters\AccessControl;
use yii\web\Controller;
use yii\web\Response;
use yii\filters\VerbFilter;
use yii\mongodb\Query;
use Symfony\Component\HttpClient\HttplugClient;
use Typesense\Client;
class UsersController extends Controller
{
public function init()
{
$client = new Client(
[
'api_key' => '',
'nodes' => [
[
'host' => 'localhost',
'port' => '8108',
'protocol' => 'http',
],
],
'client' => new HttplugClient(),
]
);
}
我什至用构造函数替换了 init()public function __construct()
但我得到了这个错误
找不到类“Typesense\Client”
在这一行为$client = new Client(
什么没有加载类?我已经检查了它在我的供应商目录中的存在。
解决方案
推荐阅读
- swift - 如何在 Swift 4 中一次解析来自分页 API 的所有数据?
- python - Plotly Dash 显示基于 SQL 查询的动态绘图数
- c++ - 调整速度值时,C++ 矩形没有正确定位?
- ms-access - 是否可以在 MS Access 中使用只读复选框的单击事件?
- recursion - 这个 Graph 的 DFS 遍历有什么问题(使用递归方法)?
- mysql - 磁盘空间不足:我的实时应用程序 mysql 数据库会损坏吗?
- amcharts - amCharts:尽管以前的 chart.homeGeoPoint,但在 JSON 数据源之后地图中心化
- bash - bits 变量的值是什么意思?
- python - 使用枚举函数 API 的意外警告 - PyCharm 错误
- bash - for loop in remotely executed bash script does not work