gpt4 book ai didi

php - 严重错误:找不到类 '..'

转载 作者:行者123 更新时间:2023-12-02 22:50:02 24 4
gpt4 key购买 nike

我正在尝试通过symfony中的PHP API使用Elasticsearch。
我已经通过Elasticsearch安装了composer

这是我的代码被称为:

<?php

namespace AppBundle\ElasticsearchQuery;
use Elasticsearch\ClientBuilder;

class ElasticsearchQuery
{
private $Host = ['http://localhost:9200'];
private $client;
private $index = "homestead";

public function __construct()
{
$this->client = Elasticsearch\ClientBuilder::create()
>setHosts($Host)->build();
}

public function execute($verb, $params)
{
switch ($verb) {
case "create":
$response = $client->index($params);
break;
case "read":
$response = $client->get($params);
break;
case "search":
$response = $client->search($params);
break;
case "delete":
$response = $client->delete($params);
break;
}
}
}

和我得到的错误:

Fatal error: Class 'AppBundle\ElasticsearchQuery\Elasticsearch\ClientBuilder' not found



我不希望它在我的AppBundle中寻找Elasticsearch,我希望它在供应商中寻找它。
我怎么做?

编辑:使用 使用\ Elasticsearch \ ClientBuilder; Elasticsearch \ ClientBuilder::create()没什么区别

最佳答案

$this->client = Elasticsearch\ClientBuilder::create()

这应该是
$this->client = \Elasticsearch\ClientBuilder::create()

或(因为您已经将该类导入了您的 namespace )
$this->client = ClientBuilder::create()

关于php - 严重错误:找不到类 '..',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36176230/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com