简体   繁体   English

致命错误:找不到类'..'

[英]Fatal error: Class '..' not found

I'm trying to use Elasticsearch via the PHP API in symfony . 我正在尝试通过symfony的PHP API使用Elasticsearch。 I have installed Elasticsearch via composer . 我已经通过composer安装了Elasticsearch

This is my code that is being called: 这是我的代码:

<?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;
    }
}
}

and the error I am getting: 和我得到的错误:

Fatal error: Class 'AppBundle\\ElasticsearchQuery\\Elasticsearch\\ClientBuilder' not found 致命错误:找不到类'AppBundle \\ ElasticsearchQuery \\ Elasticsearch \\ ClientBuilder'

I don't want it to look for Elasticsearch in my AppBundle, I want it to look for it in the vendors. 我不希望它在我的AppBundle中寻找Elasticsearch,我希望它在供应商中寻找它。 How do I do that? 我怎么做?

edit: using use \\Elasticsearch\\ClientBuilder; 编辑:使用use \\ Elasticsearch \\ ClientBuilder; or Elasticsearch\\ClientBuilder::create() makes no difference 或者Elasticsearch \\ ClientBuilder :: create()没什么区别

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

This should be either 这应该是

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

or (since you've already imported that class into your namespace) 或者(因为您已经将该类导入了命名空间)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM