Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php FOS Elastica手册供应商服务注入问题_Php_Symfony_Dependency Injection_Elastica - Fatal编程技术网

Php FOS Elastica手册供应商服务注入问题

Php FOS Elastica手册供应商服务注入问题,php,symfony,dependency-injection,elastica,Php,Symfony,Dependency Injection,Elastica,我正在尝试创建一个手动提供程序来手动填充我的FOS Elastica索引,以解释一些复杂的连接。目前,我只是想让提供程序在没有连接的情况下也能工作,而且我很难将正确的Elastica类型注入到提供程序的构造函数中。以下是我的提供者的构造函数: // ... class EmpPosDeptProvider implements ProviderInterface { private $em; protected $type; public function __con

我正在尝试创建一个手动提供程序来手动填充我的FOS Elastica索引,以解释一些复杂的连接。目前,我只是想让提供程序在没有连接的情况下也能工作,而且我很难将正确的Elastica类型注入到提供程序的构造函数中。以下是我的提供者的构造函数:

// ...
class EmpPosDeptProvider implements ProviderInterface
{

    private $em;
    protected $type;

    public function __construct(Type $type, EntityManager $em)
    {
        $this->type = $type;
        $this->em = $em->getRepository('CcitEmployeesBundle:Position');
    }
// ...
这是我的services.yml文件:

services:
    employees.search_provider.empPosDept:
        class: Ccit\EmployeesBundle\Search\EmpPosDeptProvider
        tags:
            - { name: fos_elastica.provider, index: employees, type: empPosDept }
        arguments:
            - %fos_elastica.type.class%
            - @doctrine.orm.entity_manager
当我尝试执行
php应用程序/控制台fos:elastica:populate
时,我收到以下错误:

PHP Catchable fatal error:  Argument 1 passed to Ccit\EmployeesBundle\Search
\EmpPosDeptProvider::__construct() must be an instance of Elastica\Type, string given, 
called in /vagrant-nfs/employees/app/cache/dev/appDevDebugProjectContainer.php on line 736 
and defined in /vagrant-nfs/employees/src/Ccit/EmployeesBundle/Search
/EmpPosDeptProvider.php on line 23

有人知道我需要在services.yml文件中给出什么作为正确的参数吗?或者问题完全是其他原因吗?

您传递的字符串包含
Ccit\EmployeesBundle\Search\EmpPosDeptProvider
。您必须传递
EmpPosDeptProvider
的实例,它可能会在
服务中声明。yml
类似于:

services:
    fos_elastica.type:
        class: %fos_elastica.type.class%

    employees.search_provider.empPosDept:
        class: Ccit\EmployeesBundle\Search\EmpPosDeptProvider
        tags:
            - { name: fos_elastica.provider, index: employees, type: empPosDept }
        arguments:
            - @fos_elastica.type
            - @doctrine.orm.entity_manager

显然,我需要提供指向所引用类型的显式路径。下面这句话很管用:

@fos_elastica.index.employees.employeePositionDepartment
鉴于我的config.yml文件包含以下内容,这是有意义的:

fos_elastica:
clients:
    default: { host: localhost, port: 9200 }
indexes:
    employees:
        client: default
        types:
            employeePositionDepartment:
                mappings:
                    id: { type: integer }
                    title: { type: string }
                    startDate: { type: date, format: date_time_no_millis }
                    endDate: { type: date, format: date_time_no_millis }
                    supervisor: { type: integer }

感谢所有考虑帮助我解决这个相当基本的问题的人。

嗯,你的解决方案对我不起作用。鉴于我下面的yaml文件,您知道正确的语法是什么吗?